Write a program in C to generate the first n terms of the Fibonacci Series.
Code:
#include <stdio.h>
int main()
{
int i,n,term1=0,term2=1,next;
printf("Enter number of terms: ");
scanf("%d",&n);
printf("The first %d terms of Fibonacci Series are:\n",n);
for(i=0;i<n;i++){
printf("%d, ",term1);
next = term1+term2;
term1 = term2;
term2 = next;
}
return 0;
}
Code:
#include <stdio.h>
int main()
{
int i,n,term1=0,term2=1,next;
printf("Enter number of terms: ");
scanf("%d",&n);
printf("The first %d terms of Fibonacci Series are:\n",n);
for(i=0;i<n;i++){
printf("%d, ",term1);
next = term1+term2;
term1 = term2;
term2 = next;
}
return 0;
}
No comments:
Post a Comment