用add函数求两个参数的和,并且和值返回调用函数。这个程序怎么写?

2023-07-26 14:20发布

# include void mian(){ int a = 0, b = 0, sum = 0; add();printf("%dn",su
2条回答
1楼 · 2023-07-26 14:52.采纳回答
#include<stdio.h>
#definetypeint
typeadd(typea,typeb)
{
typeret;
ret=a+b;
returnret;
}
intmain()
{
typea,b;
scanf("%d%d",&a,&b);
printf("%d\n",add(a,b));
return0;
}

#include<stdio.h>
float Add(float x,float y)//函数定义
{float s;
s=x+y;
return(s);
}
int main()
{
float x,y,sum;
char c;
while(c!='\\')//继续输入下一组数据,直到输入\键结束循环
{
printf("please input two number:\n");
scanf("%f%f",&x,&y);
printf("the result is:");
sum=Add(x,y);//调用函数,因为add函数在main函数之前定义了,所以main函数中无需再声明,而直接调用add
printf("%f\n\n",sum);
c=getchar();//
}
printf("The end\n");
getchar();//按回车键退出
}本回答被提问者采纳

2楼-- · 2023-07-26 14:51

# include <stdio.h>
void mian()
{
int a = 0, b = 0, sum = 0;
add();
printf("%d\n",sum);

}
void add()
{
int x = 0, y = 0, z = 0;
z = x + y;
return 0;
}

你试试看,应该对

一周热门 更多>