#include<stdio.h> int main() { int a[55],i,n; a[1]=1; a[2]=2; a[3]=3; for(i=4;i<55;i++) { a[i]=a[i-1]+a[i-3]; } while(scanf("%d",&n)&&n) { printf("%d\n",a[n]); } return 0; }
0.0分
0 人评分
#include<stdio.h> int main() { int cow1=0,cow2=0,cow3=0,cow4=0,mother=1,cow1_1,cow2_1,cow3_1,cow4_1,mother1; int i=1,sum,n; scanf("%d",&n); for(;i<n;i++) { cow1_1=mother; cow2_1=cow1; cow3_1=cow2; cow4_1=cow3; mother1=mother+cow4_1; cow1=cow1_1; cow2=cow2_1; cow3=cow3_1; cow4=cow4_1; mother=mother1; } sum=cow1+cow2+cow3+cow4+mother; printf("%d",sum); } 求大神指点下,怎么优化下!我个菜鸟只能到这步
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:452 |
数组输出 (C语言代码)错误???浏览:565 |
WU-陶陶摘苹果2 (C++代码)浏览:973 |
母牛的故事 (C语言代码)浏览:1428 |
用筛法求之N内的素数。 (C语言代码)浏览:664 |
矩形面积交 (C++代码)浏览:1129 |
大神老白 (C语言代码)浏览:601 |
C二级辅导-统计字符 (C语言代码)浏览:645 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:468 |
小O的乘积 (C++代码)浏览:754 |