┌──────┐
│ ↓
First Second (Next step[First])
0 1 ↑
└ + ┘ ┌────── ┘
│ │
└→Register 0+1=1
for loop:
int num,Reg,First,Second;
while(scanf("%d",&num)!=EOF){
First = 0 , Second = 1 ; //initialize both variable
printf("Fibonacci series expansion:\n");
printf("%d\n",First);
for(int i=0;i<=num;i++){ //internal for loop if set "int" a variable ,it only allowed in C99 mode that initial declaration
Reg=First + Second ;
Second = First ;
First = Reg ; //actually it transmit to the next "First"
i++;
printf("%d\n",Reg);
}
printf("The number series has F=%d",--i);
留言列表