main() { double x1=5, x2=3, r; r = fun(1, x1, x2); r += fun(2, x1, x2); printf("\nx1=%f, x2=%f, x1*x1+x1*x2=%f\n\n",x1, x2, r); } 3、编写程序,在主函数中输入两个数,调用两个子函数,分别计算两数之和与积。
时间: 2023-12-10 18:41:01 浏览: 61
用梯形法或者辛普森法数值积分-分别用Matlab和c语言实现 .docx
以下是实现该功能的代码:
```
#include <stdio.h>
double sum(double a, double b) {
return a + b;
}
double product(double a, double b) {
return a * b;
}
int main() {
double x1, x2, s, p;
printf("请输入两个数:");
scanf("%lf %lf", &x1, &x2);
s = sum(x1, x2);
p = product(x1, x2);
printf("两数之和为:%f\n", s);
printf("两数之积为:%f\n", p);
return 0;
}
```
运行结果:
```
请输入两个数:5 3
两数之和为:8.000000
两数之积为:15.000000
```
阅读全文