#include(stdio.h) // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(conio.h)
int main(void)
{
int f=0, s=1, t, n, ct;
clrscr();
printf("Enter the value of 'n': ");
scanf("%d",&n);
printf("\nFibonacci series:\n");
printf("%5d%5d", f, s);
ct=3; //becoz we already displayed 2 values and we r going the third value
while(ct<=n)
{
t=f+s;
printf("%5d", t);
f=s;
s=t;
ct++;
}
getch();
return 0;
}
Note:- here 'f' means 'first'
's' means 'second'
't' means 'third'
'ct' means 'count' the displayed numbers.
No comments:
Post a Comment