0 of 4 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 4 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
1、阅读下面长程序:
#include <iostream>
using namespace std;
int n, i, ans;
int gcd(int a, int b){
if (a % b == 0)
return b;
else
return gcd(b, a%b);
}
int main(){
cin>>n;
ans = 0;
for (i = 1;i <= n;i++)
if (gcd(n,i) == i)ans++;
cout<<ans<<endl;
}
程序输入为120,输出为
3、阅读下面程序:
#include <iostream>
using namespace std;
const int NUM = 5;
int r(int n)
{
int i;
if (n <= NUM)
return n;
for (i = 1; i <= NUM; i++)
if (r(n - i) < 0)
return i;
return -1;
}
int main()
{
int n;
cin>>n;
cout<<r(n)<<endl;
return 0;
}
输入:16 输出为:
3、阅读下面程序:
#include <iostream>
using namespace std;
int solve(int n, int m){
int i, sum;
if (m == 1) return 1;
sum = 0;
for (i = 1; i < n; i++)
sum += solve(i, m - 1);
return sum;
}
int main(){
int n, m;
cin>>n>>m;
cout<<solve(n, m)<<endl;
return 0;
}
输入:7 4 输出为:
4、阅读下面程序:
#include <iostream>
using namespace std;
int fun(int n,int fromPos,int toPos) {
int t=0,tot=0;
if(n==0)return 0;
tot=0;
tot=fun(n-1,fromPos,t);
tot++;
tot+=fun(n-1,t,toPos);
return tot;
}
int main() {
int n;
cin>>n;
cout<<fun(n,1,3)<<endl;
return 0;
}
程序输入为:5,输出结果为