题目内容

例3-4(书上)#include using namespace std;//判断n是否为回文数bool symm(unsigned n) { unsigned i = n; unsigned m = 0; while (i > 0) { m = m * 10 + i % 10; i /= 10; } return m == n;}int main() { for (unsigned m = 11; m < 1000; m++) if (symm(m) && symm(m * m) && symm(m * m * m)) { cout << "m = " << m; cout << " m * m = " << m * m; cout << " m * m * m = " << m * m * m << endl; } return 0;}试问:(1)在symm()函数中,当输入参数为523时,while循环体内容执行( )次;(2)在symm()函数中,当输入参数为1523时,while循环体内容执行( )次;

查看答案
更多问题

例3-9(书上)#include using namespace std;//计算从n个人里选k个人的组合数int comm(int n, int k) { if (k > n)return 0; else if (n == k || k == 0)return 1; elsereturn comm(n - 1, k) + comm(n - 1, k - 1);}int main() { int n, k; cout << "Please enter two integers n and k: "; cin >> n >> k; cout << "C(n, k) = " << comm(n, k) << endl; return 0;}试问:(1)comm函数输入n=9,k=5时的返回值是( )?(2)输入n=7,k=3时的返回值是( )?

例3-10(书上)//3_10.cpp#include using namespace std;//把src针的最上面一个盘子移动到dest针上void move(char src, char dest) { cout << src << " --> " << dest << endl;}//把n个盘子从src针移动到dest针,以medium针作为中介void hanoi(int n, char src, char medium, char dest) { if (n == 1)move(src, dest); else {hanoi(n - 1, src, dest, medium);move(src, dest);hanoi(n - 1, medium, src, dest); }}int main() { int m; cout << "Enter the number of diskes: "; cin >> m; cout << "the steps to moving " << m << " diskes:" << endl; hanoi(m,'A','B','C'); return 0;}试问:(1)当盘子的个数 为5时,hanoi函数被调用了( )次?(2)当盘子的个数 为10时,hanoi函数被调用了( )次?

返回值类型、参数个数、类型和顺序都相同的函数也可以重载.

A. 对
B. 错

在C++语言中,传地址调用将被引用调用所替代.

A. 对
B. 错

答案查题题库