Key Features

Experienced Teachers
Smart Classes
Regular Test
Study Material

Well qualified teachers with industrial experience.

To visualise or understand topics very easly.

We are organizing online and offline regular test.

We are providing prescribed study material.

Friday, October 30, 2020

Question : Write a C Program for Fibonacci series.

Question :   Write a C Program for Fibonacci series.


#include <stdio.h>
int main()   
{   
int n1=0,n2=1,n3,i,number;   
            printf("Enter the number of elements:");   
scanf("%d",&number);   
            printf("\n%d %d",n1,n2);//printing 0 and 1   
            for(i=2;i<number;++i)//loop starts from 2 because 0 and 1 are already printed    
            {   
                        n3=n1+n2;   
                        printf(" %d",n3);   
                         n1=n2;   
                         n2=n3;   
 } 
  return 0; 
 }
  
OUTPUT :
Enter the number of elements:15
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

Thank you very much for reading carefully, if you have any other questions, you can share it with us through comments, if this information was important to you, please let us know through comments.

Please do comment and share.
Thank You.

No comments:

Post a Comment