bLue的除法算术题 数学

来源:互联网 发布:四川网络作家协会 编辑:程序博客网 时间:2024/04/27 20:24

bLue的除法算术题

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic

Problem Description

bLue 最近接了个重活,需要帮助小学生手算大量的除法算术题,这可把他累坏了。

但是,机智的 bLue 一想,写个 “printf("%f", (double)a/b);” 不就完事了嘛。可是他最近忙得都没空开电脑啦,你能帮他写一下吗?

Input

输入数据有多组(数据组数不超过 20),到 EOF 结束。

每组输入两个整数 a, b (1 < = a, b < = 2^16) 且保证运算结果一定是有限小数。a, b 同时为 0 时输入结束。

Output

 输出 a/b 的运算结果,bLue 想要的格式参见示例。

Example Input

1 22 41 88 40 0

Example Output

0.50.50.125

2

#include<iostream>#include<cstring>#include<cstdio>using namespace std;int main(){  int a,b;  int num[20];  while(cin>>a>>b)  {     if(a+b==0)      break;    int cnt=0;    int t=a/b;    a=(a%b)*10;    while(a)    {       num[cnt++]=a/b;       a=(a%b)*10;    }    printf("%d",t);    if(cnt>0)    {      cout<<".";    for(int i=0;i<cnt;i++)      printf("%d",num[i]);     cout<<endl;   }  }  return 0;}

0 0