//Fibonacci Series using Recursion
#include<stdio.h>
int fib(int n)
{
if (n <= 1)
return n;
return fib(n-1) + fib(n-2);
}
int main ()
{
int n = 9;
printf("%d", fib(n));
getchar();
return 0;
}
#include <stdio.h>
// declaring function
int fib(int num)
{
if (num == 0)
{
return 0;
}
else if (num == 1)
{
return 1;
}
else
{
return fib(num - 1) + fib(num - 2);
}
}
int main()
{
int a;
printf("enter the number of terms you want to print
");
scanf("%d", &a);
printf("fibonacci series upto %d is : ", a);
for (int c = 0; c <a; c++)
{
printf(" %d ", fib(c));
}
return 0;
}
// Sum of fibonacci series
#include <stdio.h>
int main()
{
int fib[1000];
int num, sum = 1, i;
scanf(" %d", &num);
fib[0] = 0;
fib[1] = 1;
printf(" %d + %d", fib[0], fib[1]);
for(i = 2; i < num; i++){
fib[i] = fib[i-1] + fib[i-2];
printf(" + %d", fib[i]);
sum += fib[i];
}
printf("
= %d", sum);
return 0;
}
Fibonacchi ni c