输入正整数a,b,c,输出a/b的小数形式,精确到小数点后c位。 a,b≤106,c≤100。 输
入包含多组数据,结束标记为a=b=c=0。
样例输入:
1 6 4
0 0 0
样例输出:
入包含多组数据,结束标记为a=b=c=0。
样例输入:
1 6 4
0 0 0
样例输出:
Case 1: 0.1667
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int a,b,c;
while(cin>>a>>b>>c){
int zhengshu=a/b;
printf("%d.",zhengshu);
a=a%b;
for(int i=0;i<c;i++){
if(i==c-1){
int temp=a*10/b;
int rest=a*10%b;
int temp2=rest*10/b;
if(temp2>=5)
temp++;
printf("%d\n",temp);
break;
}
a=a*10;
printf("%d",a/b);
a=a%b;
}
}
}
本文介绍了一个使用C++编程语言实现的程序,该程序能够接收三个正整数a、b、c作为输入,并输出a/b的小数形式,精确到小数点后c位。程序通过循环处理小数部分,并在最后一位进行四舍五入。
399

被折叠的 条评论
为什么被折叠?



