Program to generate the Fibonacci sequence of numbers or Fibonacci Series.
Source Code:
#include<stdio.h>
int main()
{
int n1=0,n2=1,n3,i,number;
printf("enter the number of elements:\n");
scanf("%d",&number);
printf("\n%d,%d",n1,n2);
i=2;
while(i<number)
{
n3=n1+n2;
printf(",%d",n3);
n1=n2;
n2=n3;
i++;
}
return 0;
}
OutPut:
enter the number of elements:5
0,1,1,2,3
No comments:
Post a Comment