Fibonacci series
{
int n, first = 0, second = 1, next, i;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series:\n");
for (i = 0; i < n; ++i)
{
// Prints the first two terms as they are predefined
if(i <= 1)
next = i;
else {
next = first + second;
first = second;
second = next;
}
printf("%d\n", next);
}
return 0;
}
x
0 Comments