C Program for Fibonacci Series using While Loop

int main()
{
int f1=0,f2=1,f3,i=3,len;
printf(“enter length of the fibonacci series:”);
scanf(“%d”,&len);
printf(“%d\t%d”,f1,f2); // It prints the starting two values
while(i<=len) // checks the condition
{
f3=f1+f2; // performs add operation on previous two values
printf(“\t%d”,f3); // It prints from third value to given length
f1=f2;
f2=f3;
i=i+1; // incrementing the i value by 1
}
return 0;
}

Output for Fibonacci Series Program

enter length of the fibonacci series:10
0 1 1 2 3 5 8 13 21 34

Leave a Reply

Your email address will not be published. Required fields are marked *