输入a,b,c三个正整数,输出a/b的小数形式,精确到小数点后c位,结束标志为 a = b = c = 0;
样例输入:
1 6 4
0 0 0
样例输出:
Case 1: 0.1667
代码如下:(亲测有效)
#define LOCAL
#include <stdio.h>
#include <math.h>
int main()
{
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen ("data.out","w",stdout);
#endif
int kase = 0, a, b, c;
while(scanf("%d %d %d", &a, &b, &c) == 3 && (a != 0) && (b != 0) && (c != 0))
{
double d = (double)a/b;
int tempint = (int)d;
int tempflt = (int)(pow(10,c + 1) * (d - tempint));
if(tempflt % 10 > 5)
{
tempflt = tempflt / 10 + 1;
}
else
{
tempflt = tempflt / 10;
}
printf("Case %d:%d.%d\n",++kase, tempint, tempflt);
}
return 0;
}