gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 21:47:13 26 4
gpt4 key购买 nike

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

最佳答案

c中调用函数时,只需传递参数即可,无需指定参数类型

改变

h=add(int x, int y);

h=add(x,y);

看看这个:- http://www.techcrashcourse.com/2015/05/c-programming-function-calling.html

关于c - 给定两个整数,编写一个程序,使用函数 add() 将这些数字相加,并使用 sub() 来查找差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51361470/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com