C/C++编程学习 - 第4周 ② 甲流疫情死亡率

题目链接

题目描述

蒜头君最近研究甲流,发现:甲流并不可怕,在中国,它的死亡率并不是很高。请根据截止 2009 年 12 月 22 日各省报告的甲流确诊数和死亡数,计算甲流在各省的死亡率。

输入格式
输入仅一行,有两个整数,第一个为确诊数,第二个为死亡数,都在 [1,20000] 范围内。

输出格式
输出仅一行,甲流死亡率,以百分数形式输出,精确到小数点后 3 位。

Sample Input

10433 60

Sample Output

0.575%

思路

精确到小数点后 3 位,没什么难的。

C语言代码:

#include<stdio.h>
int main()
{
    
    
	double x, y;
	scanf("%lf%lf", &x, &y);
	double ans = (y / x) * 100;
	printf("%.3lf%%", ans);
	return 0;
}

C++代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	double a, b;
	while(cin >> a >> b)
		printf("%.3lf%\n", (b * 1.0) / (a * 1.0) * 100);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_44826711/article/details/112885596