输入两个双精准实数a,b。输出a,b进行四舍五入后相加的值
时间: 2024-06-06 07:06:35 浏览: 9
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double a, b;
cin >> a >> b;
double sum = round(a) + round(b); // 使用round函数进行四舍五入
cout << sum << endl;
return 0;
}
相关问题
C语言编写一个程序:输入两个双精度实数a,b。第一行输出a+b的真实值,第二行输出a、b进行四舍五入后再相加后的值
以下是C语言程序:
```c
#include <stdio.h>
#include <math.h>
int main()
{
double a, b;
scanf("%lf %lf", &a, &b);
printf("%.15lf %.15lf\n", a, b);
printf("%.0lf\n", round(a) + round(b));
return 0;
}
```
这个程序可以输入两个双精度实数a和b,然后输出它们的真实值和四舍五入后相加的值。注意,我们使用了math.h库中的round函数来进行四舍五入。
C语言编写一个程序:输入两个双精度实数A,B。第一行输出A+B的值结果保留五位小数。第二行输出A、B进行保留两位小数的四舍五入后再相加后的值,结果保留五位小数
以下是C语言编写的程序:
```c
#include <stdio.h>
#include <math.h>
int main() {
double a, b;
scanf("%lf %lf", &a, &b);
printf("%.5lf %.5lf\n", a, b);
double sum = round(a * 100) / 100 + round(b * 100) / 100;
printf("%.5lf\n", round(sum * 100000) / 100000);
return 0;
}
```
输入两个双精度实数A,B,程序会输出A B的值结果保留五位小数。然后,程序会输出A、B进行保留两位小数的四舍五入后再相加后的值,结果保留五位小数。