//Program to generate Fibonacci Series
#include <stdio.h>
void main()
{
int OldNum, NewNum, FibNum, MaxNum;
printf("Generate Fibonacci Numbers till what number? ");
scanf("%d", &MaxNum);
OldNum=0;
NewNum=1;
FibNum = OldNum + NewNum;
printf("%d, %d, %d, ", OldNum, NewNum, FibNum);
for( ; ;)
{
OldNum = NewNum;
NewNum = FibNum;
FibNum = OldNum + NewNum;
if(FibNum > MaxNum)
{
printf(" ");
exit(1);
}
printf("%d, ", FibNum);
}
}
No comments:
Post a Comment