给定两个整数,编写一个程序,该程序使用函数add()将这些数字相加,然后使用sub()来查找差异

时间:2018-07-16 12:06:52

标签: c

给定两个整数,编写一个使用函数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);
     ^

1 个答案:

答案 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