01 #include<iostream> 02 using namespace std; 03 const int NUM = 5; 04 int r(int n) { 05 int i; 06 if (n <= NUM) return n; 07 for (int i = 1; i <= NUM; ++i) 08 if (r(n - i) < 0) return i; 09 return -1; 10 } 11 int main() { 12 int n; 13 cin >> n; 14 cout << r(n) << endl; 15 return 0; 16 }
1. 将第 7 ⾏ i=1 改为 i=0 ,程序不会出错。( )
2. 程序输出的结果有可能⼩于 -1 。( )
3. 若输⼊的 n ⼤于等于 6 时,程序⼀定⾄少执⾏⼀次第 9 ⾏。( )
4. 若程序两次输⼊的值分别为 n1 和 n2,且有 n1 - n2 = 1 的关系,则对于这两次运⾏的结果 ans1 和 ans2,有 ans1 - ans2 = 1。 ( )
5. 若已知 $0 \leq n \leq 100$ ,则要使输出的结果为 -1 .则 n 的取值有( )种
6. 若输⼊ 2020 ,输出的结果为( )