问题 填空题

有以下程序:
#include <stdio.h>
int sub(int n)
return(n/10 + n% 10);
main( )
int x,y;
seanf(" %d" , &x); y = sub (sub(sub (x)));
printf(" %d \n";,y);
若运行时输入:1234<回车>,程序的输出结果是 【13】

答案

参考答案:J

解析: 函数sub递归调用的返回值被作为再次调用sub函数的实参传给函数sub的形参,共进行3次递归调用。第1次调用sub(1234)的返回值为1234/10+1234%10=127;第2次调用sub(127)的返回值为127/10+127%10=19;第3次调用sub(19)的返回值为19/10+19% 10=10。所以程序的输出为10。

单项选择题
填空题