用C语言编写两个数求和求积求商?

2024-12-17 14:35:39
推荐回答(4个)
回答1:

//用C语言编写两个数求和求积求商?
#include
float add(float x,float y)
{
float z;
z=x+y;
return z;
}float multiply(float x,float y)
{
float z;
z=x*y;
return z;}float divide(float x,float y)
{
float z;
z=x/y;
return z;
}void main()
{
float a,b;
printf("请分别输入两个数:");
scanf("%f%f",&a,&b);
printf("%.2f+%.2f=%.2f\n",a,b,add(a,b));
printf("%.2f*%.2f=%.2f\n",a,b,multiply(a,b));
printf("%.2f/%.2f=%.2f\n",a,b,divide(a,b));}

回答2:

main(){int a,b,sum=0,c=0,d=0;scanf("%d%d",&a,&b);//从键盘任意输入2个整数sum=a+b;//求和c=a*b;//求积d=a/b;//求商printf("sum=%d,c=%d,d=%d",sum,c,d);//输出和,积,商}

回答3:

#include
int main()
{
float a , b;
printf("输入2个数:\n");
scanf("%f%f",&a,&b);
printf("和:%f\n积:%f\n商:%f\n",a+b,a*b,a/b);
return 0;
}

回答4:

#include
main()
{
float a,b;
printf("Please enter two values:");
scanf("%d%d",&a,&b);
printf("a+b=%f, a*b=%f, a/b=%f",a+b, a*b, a/b);
}