bLue 最近接了个重活,需要帮助小学生手算大量的除法算术题,这可把他累坏了。
但是,机智的 bLue 一想,写个 “printf("%f", (double)a/b);” 不就完事了嘛。可是他最近忙得都没空开电脑啦,你能帮他写一下吗?
输入数据有多组(数据组数不超过 20),到 EOF 结束。
每组输入两个整数 a, b (1 < = a, b < = 2^16) 且保证运算结果一定是有限小数。a, b 同时为 0 时输入结束。
Output
输出 a/b 的运算结果,bLue 想要的格式参见示例。
Sample Input
1 2
2 4
1 8
8 4
0 0
Sample Output
0.5
0.5
0.125
2
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
int b[100],q,p,i,t,ans;
while(~scanf("%d%d",&q,&p)&&q&&p)
{
t=0;
memset(b,0,sizeof(b));
ans=q/p;
q=q%p*10;
while(q)
{
b[t++]=q/p;
q=q%p*10;
}
printf("%d",ans);
if(t>0)
{
printf(".");
for(i=0;i<t;i++)
{
printf("%d",b[i]);
}
}
printf("\n");
}
return 0;
}