蓝桥杯 adv238 P0101

蓝桥杯 adv238 P0101

题目描述

一个水分子的质量是3.0*10-23克,一夸脱水的质量是950克。写一个程序输入水的夸脱数n(0<= n <= 1e10),然后输出水分子的总数。

输入

109.43

输出

3.465283E+027

参考解答

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double n, ans;
cin >> n;
ans = n * 950 / 3.0;
if(ans == 0) {
printf("0.000000E+000");
} else if (ans >= 1){
int num = log10(ans); // 查看一个数科学记数法有几个零的神奇方法
printf("%6fE+%03d", ans/pow(10,num), 23+num);
}else{
int num = 1 - log10(ans);
printf("%6fE+%03d", ans*pow(10,num), 23-num);
}
return 0;
}

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×