A Fibonacci sequence is defined as follows: the first and second terms in the sequence are 0 and 1. Subsequent terms are found by adding the preceding two terms in the sequence. Write a C program to generate the first n terms of the sequence.

Program Code:
#include<stdio.h>
void main()
{
int a,b,n,c,i;
printf("\n Enter a number of terms:");
scanf("%d",&n);
a=0;
b=1;
for(i=0;i<=n-2;i++)
{
if(a==0 && b==1)
printf("the fibonacci sequence is %d\t%d",a,b);
c=a+b;
printf("\t%d",c);
a=b;
b=c;
}
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: