求大佬指点!
当if后面没有return age时,输出的年龄为8岁,加上后年龄为18,求解释
#include <stdio.h>
int people(n)
{ int age;
if(n==1){age=10;return age;}
else
{age=people(n-1)+2;
return age;
}
}
int main()
{
int fifthage=people(5);
printf("第5个人的年龄是%d岁", fifthage);
return 0;
}
当if后面没有return age时,输出的年龄为8岁,加上后年龄为18,求解释
#include <stdio.h>
int people(n)
{ int age;
if(n==1){age=10;return age;}
else
{age=people(n-1)+2;
return age;
}
}
int main()
{
int fifthage=people(5);
printf("第5个人的年龄是%d岁", fifthage);
return 0;
}
2017-11-01
举报