下面程序尝试使用空间换取时间的策略实现第1至100项中任意菲波那切数列的求解,请填空完善程序。# include <stdio.h># define N 100int fab[N]={-1};int Fab(int n){if (___________){if ((n==1)||(n==2))fab[n]=1;elsefab[n]=Fab(n-1)+Fab(n-2);}return fab[n];}int main(){int n;scanf("%d",&n);printf("%d",Fab(n));return 0;}?
举一反三
- 程序填空,使下面程序实现输出N!(N<=10000)的最低三位。#include <stdio.h>int main(){int N,M=1;scanf("%d",&N);for (int i=1;i<=N;i++){M=M*i;M=__________;}printf("%03d",M);return 0;}?
- 写出下面程序执行后的运行结果。#include <stdio.h>int main(){int i,n[]={0,0,0,0,0};for(i=1;i<=4;i++) {n[i]=n[i-1]*2+1;printf("%d:",n[i]);} return 0;}?
- 下面程序执行的结果是 。#include<;stdio.h>;int f(int );int main(){int z;z=f(5);printf("%d\n",z);return 0;}int f(int n){if(n==1||n==2)return 1;elsereturn f(n-1)+f(n-2);}
- 以下程序的输出结果是______ 。#include int f(int n) { if(n == 1) return 1; else return n + f(n - 1);}int main(void) { printf("%d\n", f(5)); return 0;}
- 执行以下程序后,如果输入为1,则输出为,如果输入为0,则输出为,如果输入为4,则输出为。#include<;stdio.h>;int f(int n);int main(){int n;scanf("%d",&n);printf("%d\n",f(n));return 0;}int f(int n){if(n==0||n==1)return 1;elsereturn f(n-1)+f(n-2);}