C语言基础代码打不对
#include <stdio.h>main(),
{
int a,b,sum;
printf("please input two numbers:\n");
scanf("%d%d",&a,&b);
sum=add(a,b);
printf("%d+%d=%d",a,b,sum);
}
int add(int a,int b)
{
int c;
c=a+b;
return c;
}
错误码:
data definition has no type or storage class
expected identifier or '(' before '{' token
recipe for target 'main.o' failed
add函数应该放在main函数前面
#include <stdio.h>
int add(int a, int b)
{
int c;
c = a + b;
return c;
}
int main(void)
{
int a, b, sum;
printf("please input two numbers:\n");
scanf("%d%d",&a,&b);
sum = add(a, b);
printf("%d + %d = %d\n", a, b, sum);
return 0;
} 本帖最后由 boot 于 2018-1-31 16:03 编辑
你书里的程序有错误
main后的逗号去掉
int add(int a,int b);这句加到main和include中间
或者 加在main函数里。你要调用函数,必须要声明函数。
最后问一句,你是不是要考二级呀
{:10_256:}{:10_256:}{:10_256:} boot 发表于 2018-1-31 15:59
你书里的程序有错误
main后的逗号去掉
int add(int a,int b);这句加到main和include中间
没有,我毕业很久了,大脑开始退化了,刚好最近上班比较闲,当成兴趣读读看。 没错 一般函数写在主程序之前,否则需声明
页:
[1]