22. 分数化小数 decimal

题目:

输入正整数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;}

原文地址:https://www.cnblogs.com/Hello-Nolan/p/12122189.html

时间: 2024-10-12 07:46:20

22. 分数化小数 decimal的相关文章

分数化小数(decimal) 白书习题 2-5

1 /* 2 分数化小数(decimal) 白书习题 2-5 3 输入正整数 a , b , c , 输出 a/b 的小数形式,精确到小数点后 c 位 .a,b<=10^6 , c <= 100. 4 输入包含多组数据,结束标志为 a = b = c = 0 ; 5 */ 6 #include<stdio.h> 7 int main() 8 { 9 int a,b,c,y; //y用来存储 a/b 的余数 10 while(scanf("%d%d%d",&

分数化小数

Fractions to Decimals Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator and print the decimal representation.If the decimal representation has a repeating sequence of digits, indicate the s

【模拟】10216 - 分数化小数

[模拟]10216 - 分数化小数 Time Limit: 1000MS Memory Limit: 25600KB 30分骗分算法 # include<cmath> # include<stdio.h> # include<stack> # include<iostream> # include<algorithm> using namespace std; stack<int>S; const int maxn=10000; in

[LeetCode]58. Fraction to Recurring Decimal分数化小数

Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. For example, Given numerator = 1, denominator = 2, retu

白书p35 习题2-4 分数化小数(decimal)

#include<stdio.h> int main() { int a,b,c; while(scanf("%d%d%d",&a,&b,&c)!=EOF) { if(a==0&&b==0&&c==0) break; int y=a%b; printf("%d.",a/b); for(int i=0;i<c-1;i++) { y*=10; printf("%d",y/b);

每日一练第5天:分数化小数

输入正整数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 这道题靠计算机本身来做除法是会出现精度问题的,所以要模拟数学上的除法: 1 #include <stdio.h> 2 3 int main() 4 { 5 int a, b, c, ct = 1; 6 while(3 == scanf("%d%d%d",

分数化小数(C++)

输入整数a, b ,c, 输出a/b的小数形式,精确到小数点后c位,a, b ≤ 10^6, c ≤ 100.输入包含多组数据, 结束标记为a = b = c = 0. 答案如下 #include<iostream> #include<cmath> using namespace std; int main() { int a, b, c, m; int con[100]; cin >> a >> b >> c; while (a != 0 &a

紫书 习题2-5 分数化小数

1 #include<stdio.h> //基础版 2 #define MAX 110 3 4 int main(void) 5 { 6 int a, b, c; 7 scanf("%d %d %d",&a,&b,&c); 8 9 int integer = a/b; 10 int remainderTemp=a%b; 11 int arr[MAX]; 12 13 for(int i = 0; i< c; i++){ 14 int result

[Swift]LeetCode166. 分数到小数 | Fraction to Recurring Decimal

Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. Example 1: Input: numerator = 1, denominator = 2 Output