函数调用实现加减乘除
目的实现加减乘除#include <stdio.h>
#include <stdlib.h>
double add(double, double);
double sub(double, double);
double mul(double, double);
double divi(double, double);
double add(double a, double b)
{
double result;
result = a + b;
return result;
}
double sub(double a, double b)
{
double result;
result = a - b;
return result;
}
double mul(double a, double b)
{
double result;
result = a * b;
return result;
}
double divi(double a, double b)
{
if (b == 0)
{
printf("除数不能为零!");
}
else
{
double result;
result = a + b;
return result;
}
}
int main()
{
double a, b;
printf("请输入两个数:");
scanf("%f %f", &a, &b);
printf("对这两个数进行加减乘除后的结果是:%.2f %.2f %.2f %.2f\n", add(a, b), sub(a, b), mul(a, b), divi(a, b));
return 0;
} scanf("%lf %lf", &a, &b);
double型的要用 %lf double divi(double a, double b)
{
if (b == 0)
{
printf("除数不能为零!");
exit(1);
}
else
return a+b;
}
scanf("%lf %lf", &a, &b); 大马强 发表于 2021-8-1 19:07
double型的要用 %lf
{:10_275:}原来是这样 万千只cnm 发表于 2021-8-1 19:32
我还发现我除法写错了{:10_262:}
页:
[1]