Answer: A function fibonacci(n) starts with a = 0, b = 1 and repeatedly prints a and moves forward (c = a + b; a = b; b = c).
Logic: each Fibonacci term is the sum of the previous two: 0, 1, 1, 2, 3, 5, 8, …
Program:
#include <stdio.h>
void fibonacci(int n)
{
int a = 0, b = 1, c, i;
for (i = 1; i <= n; i++)
{
printf("%d ", a);
c = a + b;
a = b;
b = c;
}
printf("\n");
}
int main()
{
int n;
printf("Enter number of terms: ");
scanf("%d", &n);
fibonacci(n);
return 0;
}Sample output (actual run):
Enter number of terms: 8
0 1 1 2 3 5 8 13