Fibonacci Series Program in C | C Program to Display Fibonacci Sequence

Fibonacci Series Program in C | C Program to Display Fibonacci Sequence 

fibonacci series program |  fibonacci series in c using recursion

fibonacci series program |  fibonacci series in c using recursion

  1. #include<stdio.h>    
  2. int main()    
  3.  int n1=0,n2=1,n3,i,number; 
  4.  printf("Enter the number of elements:"); 
  5.  scanf("%d",&number);    
  6.  printf("\n%d %d",n1,n2); 
  7.  for(i=2;i<number;++i) 
  8.  {
  9.   n3=n1+n2; 
  10.   printf(" %d",n3); 
  11.   n1=n2; 
  12.   n2=n3;
  13.  }
  14.   return 0;  
  15.  } 
Out Put 
Enter the number of elements:15
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 233 377

fibonacci series program | Fibonacci Series using recursion in C

  1.  #include<stdio.h>    
  2. void printFibonacci(int n){    
  3.  static int n1=0,n2=1,n3;    
  4.    if(n>0){    
  5. n3 = n1 + n2;    
  6. n1 = n2;    
  7.  n2 = n3;    
  8. printf("%d ",n3);    
  9. printFibonacci(n-1);    
  10.  }    
  11. }    
  12. int main(){    
  13. int n;    
  14. printf("Enter the number of elements: ");    
  15. scanf("%d",&n);    
  16. printf("Fibonacci Series: ");    
  17. printf("%d %d ",0,1);    
  18. printFibonacci(n-2);
  19. return 0;  
  20.  }    

Output:

Enter the number of elements:15
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

fibonacci series in c using function | Display Fibonacci series in C within a range using a function 



Enter range: 20
The fibonacci series is:
0 1 1 2 3 5 8 13

fibonacci series in c using for loop 

#include<stdio.h>
#include<conio.h>

int main () { int first = 0, second = 1, third, i, n; printf ("Enter the length of the fibonacci series \n"); scanf ("%d", &n); printf ("The Fibonacci series is :\n"); printf ("%d%d", first, second); for (i = 2; i <= n; i++) { third = first + second; printf ("%d ", third); first = second; second = third; } return 0;
}

 OUTPUT:

Enter the length of the fibonacci series
10
The Fibonacci series is :
011 2 3 5 8 13 21 34 55

fibonacci series in c using while loop | C Program for Fibonacci Series using While Loop

#include<stdio.h>

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); while(i<=len) { f3=f1+f2; printf("\t%d",f3); f1=f2; f2=f3; i=i+1; } return 0;
}
enter length of the fibonacci series:10
0 1 1 2 3 5 8 13 21 34

Fibonacci Series Program in C | C Program to Display Fibonacci Sequence .

  • C Program to Display Fibonacci Sequence
  • fibonacci series program
  • fibonacci series in c using recursion
  • fibonacci series in c using function
  • fibonacci series in c using for loop 
  • fibonacci series in c using while loop
Next Post Previous Post
No Comment
Add Comment
comment url