题目:
输入正整数a, b,c,输出 a / b 的小数形式,精确到小数点后 c 位。a ,b <= 10^6, c <= 100。输入包含多组数据,结束标记为 a = b = c = 0.
样例输入:
1 6 4
0 0 0
样例输出:
Case 1: 0.1667
思路:
按照步骤计算即可。
代码:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int a = 0, b = 0, c = 0;
int kase = 0;
while ((cin >> a >> b >> c) && a && b && c) {
double result = static_cast<double>(a) / b;
cout << "Case " << ++kase << ": ";
cout << setprecision(c) << fixed << result << endl;
}
return 0;
}