我這個怎么輸出 第5個人的年齡是10歲?求解。
#include
int getAge(numberpeople)
{ ? ?//定義年齡
? ?int age;
? ?//如果是第一個人的話,年齡是10歲
? ?if(numberpeople=1)
age =10;
else
age=getAge(numberpeople-1)+2;
return age;
}
int main()
{
int fifthAge= getAge(5);
printf("第5個人的年齡是%d歲",fifthAge);
return 0;
? ?
}
2017-03-21
#include <stdio.h>
int getAge(int numberpeople) ? // 這里要一個int
?{
//定義年齡
int age;
//如果是第一個人的話,年齡是10歲
if(numberpeople==1) age =10; ? ?// 這里是等于 ?不是把1賦給numberpeople;
else
age=getAge(numberpeople-1)+2;
return age;
}
int main() {
int fifthAge= getAge(5);
printf("第5個人的年齡是%d歲",fifthAge);
return 0;
}
2017-03-13
?#include
int getAge(numberpeople)?
{
if(numberpeople=1) ? ? ? ? ?/*你這個地方寫錯了,應(yīng)該是numberpeople==1而不是numberpeople=1*/
age =10;?
else age=getAge(numberpeople-1)+2;?
return age; }?
int main()?
{?
int fifthAge= getAge(5);?
printf("第5個人的年齡是%d歲",fifthAge);?
return 0; ? ?
?}
2017-03-07
if() {
}else {
}