How to find time complexity of nested loops? also, how to find time complexity of a program consisting of more than one functions?
Basically, I'm confused when to add/multiply the time complexities.
#include <stdio.h>
long pascal(int, int);
int main()
{
int n,m,k,j;
printf ("Enter the height for Pascal's Triangle: ");
scanf("%d", &n);
for(k = 0; k<n; k++)
{
for(j = 0; j < n-k; j++)
{
printf(" ");
}
for(m = 0; m <= k; m++)
{
long f = pascal(k, m);
printf("%ld ", f);
}
printf("\n");
}
return 0;
}
long pascal(int n, int i)
{
if(n == i || i == 0)
return 1;
else
return pascal(n-1, i) + pascal(n-1, i-1);
}
This was the code I used for printing Pascal's triangle. How to find its time complexity?