Fibonacci Series Using For Loop in C


Q. Write a C program for Fibonacci Series using for loop.

#include    
void main()    
{    
    int n1=0,n2=1,n3,n;    
    printf("Enter the number:");    
    scanf("%d",&n);    
    printf("Fibonacci series terms are:\n%d %d",n1,n2);
    for(int i=2;i<n;i++)  
    {   
    	n3=n1+n2;    
        n1=n2;    
        n2=n3; 
        printf(" %d",n3);       
    }  
}

Q. Write an algorithm to Fibonacci Series using for loop.

1. Start
2. Declare three integer variables: `a`, `b`, and `c`.
3. Display the message: "Enter the numbers:"
4. Read two integers from the user and store them in `a` and `b`.
5. Calculate the sum of `a` and `b` and store the result in `c`:
    - `c = a + b`
6. Display the message: "Addition Of Two Number is: " followed by the value of `c`.
7. End



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.