C语言入门程序
有5个人坐在一起,问第5个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。问第3个人,又说比第2人大两岁。问第2个人,说比第1个人大两岁。最后 问第1个人,他说是10岁。请问第5个人多大?
#include <stdio.h>
int age(n)
{
int num;
if(n==1)
{
num=10;
}else{
num=age(n-1)+2;
}
return num;
}
int main()
{
int a=age(5);
printf("第5个人的年龄是%d岁", a);
return 0;
}
错误如下:
cpp:2: error: `n' was not declared in this scope
cpp:3: error: expected `,' or `;' before '{' token
cpp:17: error: `age' cannot be used as a function
不知道什么情况
最佳答案
你的
int age(n)
根本不是C的语法
正确的是
int age(int n)
其他回答
其它网友回答:
[url=http://www.51zxw.net/study.asp?vip=14825577]让学习变得很轻松[/url]