📅  最后修改于: 2022-03-11 15:04:40.546000             🧑  作者: Mango
1, 1, 2, 3, 5, 8
#include
void main()
{
int s1=0,s2=1; //initializing first two numbers
int nextNum=0,SumUpto=0;
printf("\n\n\tPlease enter number up to which print Fibonacci series is required \t");
scanf("%d",&SumUpto);
//here assuming user will enter value more than 1
//printing first two numbers
printf("\n\tfibbonacci Series up to %d is ",SumUpto);
printf("\n\n\t%d %d",s1,s2);
for(nextNum=2;nextNum<=SumUpto;)
{
s1=s2;
s2=nextNum;
printf(" %d",nextNum);
nextNum=s1+s2;
}
}