#CS40510. 阅读程序5-递推与递归10
阅读程序5-递推与递归10
阅读程序
注意:切勿用电脑直接运行代码得出答案,请用大脑+笔+纸运行代码答题,否则是在浪费你的时间。
第10题【NOIP】2014
#include <iostream>
using namespace std;
int fun( int n, int minNum, int maxNum ){
int tot, i;
if ( n == 0 )return 1;
tot = 0;
for ( i = minNum; i <= maxNum; i++ )
tot += fun( n - 1, i + 1, maxNum );
return(tot);
}
int main(){
int m;
scanf( "%d", &m );
printf( "%d\n", fun( m, 1, n ) );
return(0);
}
●判断题
(1)将第5行删掉,程序编译错误。
{{ select(10-1) }}
- 正确
- 错误
(2)当输入的n的绝对值在1000以内时,程序不一定能正常运行
{{ select(10-2) }}
- 正确
- 错误
(3)将第4行的内容接在第2行后,程序输出与原样不同
{{ select(10-3) }}
- 正确
- 错误
(4)将第4行的内容去掉,程序推会运行错误。
{{ select(10-4) }}
- 正确
- 错误
●选择题
(5)fun(2,1,6)的值为( )
{{ select(10-5) }}
- 15
- 10
- 6
- 3
(6)fun(3,1,6)的值为( )
{{ select(10-6) }}
- 20
- 10
- 4
- 1
相关
在以下作业中: