C Programming Lab Manual – 2

Write a C program to generate the first n terms of the Fibonacci sequence.

Read the number of terms n
Initialize a = 0, b = 1 
print a and b values
for i = 3 to n
increment the i value
c = a+b
print c value
a = b
b = c
#include<stdio.h>
int main()
{
int a=0,b=1,c,n,i;
printf("Enter no. of terms:");
scanf("%d", &n);
printf("The Fibonacci sequence is:");
printf("%d%d", a,b);
for(i=3;i<=n;i++)
{
c=a+b;
printf("%d",c);
a=b;
b=c;
}
return 0;
getchar();
}

Enter no. of terms:5

The Fibonacci sequence is:01123