给定两个整数,编写一个使用函数add()将其相加的程序 数字和sub()来找到区别...开始编码..有人 告诉什么可能的错误
#include<stdio.h>
int add(int a,int b); //function declaration
int sub(int a,int b);
int main()
{
int t,h,x,y;
x=20;y=10;
h=add(int x, int y); //function call
printf("addition of two no is %d",h);
t= sub(int x, int y);
printf("sub of two no is %d",t);
return 0;
}
int add(int a,int b) //function definition
{
int h=a+b;
return h;
}
int sub(int a,int b)
{
int t=a-b;
return t;
}
编译结果:
errors:expected expression before 'int'
h=add(int x, int y);
^
main.c:8:7: error: too few arguments to function 'add'
h=add(int x, int y);
^
main.c:2:5: note: declared here
int add(int a,int b);
^
main.c:10:9: error: expected expression before 'int'
t= sub(int x, int y);
^
main.c:10:5: error: too few arguments to function 'sub'
t= sub(int x, int y);
^
main.c:3:5: note: declared here
int sub(int a,int b);
^
答案 0 :(得分:-1)
在parameters
中调用parameter type
时,只需传递function
,而无需指定c
。
更改
h=add(int x, int y);
到
h=add(x,y);
看看这个:-http://www.techcrashcourse.com/2015/05/c-programming-function-calling.html