0 1 1 2 3 5 8 13 21 ...
/* Using while loop */
#include<stdio.h>
void main()
{
int n,i,a,b,c;
printf("Enter th number of terms: ");
scanf("%d",&n);
i=1;
a=0;
b=1;
while(i<=n)
{
printf("%d ",a);
c = a + b;
a = b;
b = c;
i++;
}
}
/* Using for loop */
#include<stdio.h>
void main()
{
int n,i,a,b,c;
printf("Enter th number of terms: ");
scanf("%d",&n);
a=0;
b=1;
for(i=1;i<=n;i++)
{
printf("%d ",a);
c = a + b;
a = b;
b = c;
}
}
0 Comments