1087-分数化小数

Description

输入正整数a、b、c,输出a/b的小数形式结果,精确到小数点后c位。a,b≤106,c≤100。

Input

输入数据有多组,每组包括三个正整数a、b、c,单独占一行。最后一组三个0表示输入结束,不需处理。

Output

对于每组输入数据,输出对应的结果,每组输出占一行。

Sample Input

1 6 4
2 4 2
0 0 0

Sample Output

0.1667
0.50


#include <stdio.h>
int main()
{
    char str[10];
    int a,b,c;
    double f;
    while (scanf("%d%d%d",&a,&b,&c))
    {
        if (a==0 && b==0 && c==0)
            break;
        f = a*1.0/b;
        sprintf(str,"%%.%dlf\n",c);
        printf(str,f);
    }

    return 0;
}

sprintf()函数:将本该输出到控制台的字符串保存在字符串数组中

 

posted @ 2019-01-24 10:14  路漫漫我不畏  阅读(206)  评论(0编辑  收藏  举报