思考:这道题考验的是罗辑思维,这个网址http://blog.csdn.net/sxhelijian/article/details/42609353的罗辑思维值得学习
#include<stdio.h> int main() { int n; char d; int f1,f2,f3,fn; while(scanf("%d%c",&n,&d)!=EOF) { f1=1; f2=2; f3=3; if(n==0) break; if(n==1) printf("%d\n",f1); else if(n==2) printf("%d\n",f2); else if(n==3) printf("%d\n",f3); else { for(int i=4;i<=n;i++) { fn=f3+f1; f1=f2; f2=f3; f3=fn; } printf("%d\n",fn); } } }
时间: 2024-10-25 14:56:04