Problem Description
计算A/B的精确值,设A、B是以一般整数输入,计算结果精确到小数点后20位(若不足20位,末尾不用补0)
Input
输入有多组数据,每组数据为两个数A和B
Output
对于每组数据输出A/B的精确值
Sample Input
2 4 3 30 6
Sample Output
4/3=1.33333333333333333333 30/6=5.0
//标程:
#include<stdio.h> #include<string.h> int a[25]; int main() { //freopen("a.txt","r",stdin); int t,x,y,i,j; scanf("%d",&t); while(t--) { memset(a,0,sizeof(a)); scanf("%d%d",&x,&y); a[0]=x/y; if(x%y==0) { printf("%d/%d=%d.0\n",x,y,a[0]); continue; } printf("%d/%d=%d.",x,y,a[0]); int temp=x%y; for(i=1;i<21;) { temp=temp*10; a[i++]=temp/y; temp=temp%y; } for(i=20;i>0;i--) if(a[i]!=0) break; for(j=1;j<=i;j++) printf("%d",a[j]); printf("\n"); } return 0; }