题目
输入正整数a,b,c,输出a/b的小数形式,精确到小数点后c位。
a,b<=106,c<=100。
输入包含多组数据,结束标记为a=b=c=0。
样例输入:
1 6 4
0 0 0
样例输出:
Case 1:0.1667
代码:
#include<iostream>
using namespace std;
int main()
{
int count = 0;
while (true)
{
float a = 0, b = 0, c = 0;
cin >> a >> b >> c;
//退出循环条件
if (a == 0 && b == 0 && c == 0) break;
float d;
d = a / b;
count++;
cout << "Case" << count << ":";
//若精度不足,则补足
cout.flags(ios::fixed);
//设置输出精度
cout.precision(c);
cout << d;
cout << endl;
}
return 0;
}
有关于cout的操作,推荐大家看我的另一篇文章,cout的输出控制。