Lyke9883139
2019-06-16 09:50
答案里面的numPeople从未定义
#include <stdio.h> int getAge(int numPeople) { int age; if (numPeople == 1) return 10; else age = getAge(numPeople - 1) + 2; return age; } int main(){ printf("第5个人的年龄是%d岁", getAge(5)); return 0; }
numPeople是形参,在main()函数中调用时赋值
int digui(int num){
int result;
if(num<1){
printf("数据错误");
return 0;
}else if(num == 1){
result=10;
}else{
result = digui(num-1)+2;
}
return result;
}
C语言入门
926206 学习 · 20797 问题
相似问题