Fibonacci Series Program in C | C Program to Display Fibonacci Sequence
fibonacci series program | fibonacci series in c using recursion
- #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);
- for(i=2;i<number;++i)
- {
- n3=n1+n2;
- printf(" %d",n3);
- n1=n2;
- n2=n3;
- }
- return 0;
- }
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
- #include<stdio.h>
- void printFibonacci(int n){
- static int n1=0,n2=1,n3;
- if(n>0){
- n3 = n1 + n2;
- n1 = n2;
- n2 = n3;
- printf("%d ",n3);
- printFibonacci(n-1);
- }
- }
- int main(){
- int n;
- printf("Enter the number of elements: ");
- scanf("%d",&n);
- printf("Fibonacci Series: ");
- printf("%d %d ",0,1);
- printFibonacci(n-2);
- return 0;
- }
Output:
Enter the number of elements:150 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 series10The 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:100 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
Tags:
C Programming