分数的精度

   1 #include <stdio.h>
  2
  3 int main()
  4 {
  5     int m , n, i ,j;
  6     int quotient[1010];
  7     int remainder[1001];
  8     printf("Please input a fraction (m/n)(<0<m<n<=100):");
  9     scanf("%d/%d", &m, &n);
 10     printf("%d/%d it's accuracy value is: 0.", m ,n);
 11     for (i = 1; i <= 100; i++)
 12     {
 13         remainder[m]=i;
 14         m*=10;
 15         quotient[i]=m/n;
 16         m = m%n;
 17         if (0 ==m)
 18         {
 19             for (j =1 ;j <= i; j++)
 20             printf("%d", quotient[j]);
 21             break;
 22         }
 23         if (remainder[m]!=0)
 24         {
 25             for (j = 1; j <= i; j++)
 26             printf("%d", quotient[j]);
 27             printf("\n\tand it is a infinite cuclic fraction from %d\n", remainder[m]);
 28             printf("\tdigit to %d digit after decimal point.\n", i);

 29             break;

 30         }
 31     }
 32     return 0;
 33 }

[root@localhost 47]# vim fraction_accuracy_value.c 
[root@localhost 47]# ./a.out 
Please input a fraction (m/n)(<0<m<n<=100):25/96
25/96 it's accuracy value is: 0.260416
        and it is a infinite cuclic fraction from 6
        digit to 6 digit after decimal point.
[root@localhost 47]# ./a.out 
Please input a fraction (m/n)(<0<m<n<=100):23/87
23/87 it's accuracy value is: 0.2643678160919540229885057471
        and it is a infinite cuclic fraction from 1
        digit to 28 digit after decimal point.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值