Write and run the following programmes in C-language
and calculate its total time complexity.
Generate a Fibonaci
series of 10 numbers.
Ans
#include<stdio.h>
int fib(int n){
if (n==0 || n==1)
return n;
else
return fib(n-1)+fib(n-2);
}
int main(){
int i;
for (i=0; i<10; i++)
printf("%d ", fib(i));
return 0;
}
No comments:
Post a Comment