Fibonacci series in c using for loop

In this example, I shared fibonacci series in c using for loop of n terms. Learn about loops like for, while, do-while.

C Fibonacci Series


For example, if the user enters 10 then the output will be:

Fibonacci series of 10 terms:-
0
1
1
2
3
5
8
13
21
34




#include<stdio.h>
int main()
{
   int n,f0,f1,i,fib;
    printf("\n Enter the number of terms:");
    scanf("%d",&n);
    printf("\n Fibonacci series of %d terms:-",n);
        f0=0;
        f1=1;
    printf("%d\n",f0);
    printf("%d\n",f1);
     for(i=3;i<=n;i++)
     {
       fib=f0+f1;
       printf("%d\n",fib);
        f0=f1;
        f1=fib;
     }
 return 0;
}

NOTE: You have any problem in above fibonacci series in c do not hesitate and write your problem in the comment box. I will support your problem.

No comments:

If you have any doubts, Please let me know

Powered by Blogger.