C Program to generate n fibonacci Series.

 #include<stdio.h>

main()

{

int f1=0,f2=1,f3,n,i;

clrscr();

printf("\nEnter the nth number");

scanf("%d",&n);

printf("\nFirst %d Fibonacci numbers are :",n);

if(n==1)

{

printf("\n%d",f1);

}

if(n==2)

printf("\n%d %d\t",f1,f2);

else

{

printf("%d\t%d\t",f1,f2);

i=2;

while(i<n)

{

f3=f1+f2;

printf("%d\t",f3);

f1=f2;

f2=f3;

i++;

}

}

getch();

}


Output:

  1. Enter the nth number

5

First 5 Fibonacci numbers are:

0     1       1       2       3


  1. Enter the nth number

10

First 10 Fibonacci numbers are:

0       1       1       2       3       5     8       13      21    34



Post a Comment

Previous Post Next Post