Print Fibonacci series up to n terms with C.
#include <stdio.h>
int main()
{
int a, b, c, i, terms;
printf("Enter number of terms: ");
scanf("%d", &terms);
a = 0;
b = 1;
c = 0;
printf("Fibonacci terms: \n");
for (i = 1; i <= terms; i++)
{
printf("%d, ", c);
a = b;
b = c;
c = a + b;
}
return 0;
}
Output:-
Enter number of terms : 10
Fibonacci terms : 0 1 1 2 3 5 8 13 21 34
0 Comments