问题描述:
输入正整数a,b,c,输出a/b的小数形式,保留小数点后c位。a,b<=1000000,c<=100输入包含多组数据,结束标记a=b=c=0.
样例输入:
1 6 4
0 0 0
样例输出:
Case 1:0.1667
#include <iostream>
using namespace std;
int main(){
long long a = 0,b=0;
int c = 0,temp = 0;
while (cin>>a>>b>>c) {
temp = a/b;
cout<<temp<<".";
for(int i = 0;i < c;++i){
a = a%b*10;
temp = a/b;
if(i == c-1 && a%b*10/b>5)
temp ++;
cout<<temp;
}
}
return 0;
}
当数据超过long long长度的时候,存在越界,还没想好怎么用一个简洁的方法处理。
作者:include4229
来源:CSDN
原文:https://blog.csdn.net/include4229/article/details/83831170
版权声明:本文为博主原创文章,转载请附上博文链接!