bLue的除法算术题

Time Limit: 1000MS Memory Limit: 65536KB

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 2
2 4
1 8
8 4
0 0

Example Output

0.5
0.5
0.125
2

Hint

Author

「2016级ACM集训队第一次选拔赛」bLue    



// by bLue

#include <stdio.h>

int main() {
	int a, b;
	while(scanf("%d %d", &a, &b), a|b) {
		int integer = a/b;	// 整数部分
		int decimal[20];	// 存储每一位小数
		int cnt = 0;	// 小数位数
		a = (a%b)*10;	// 已计算出整数部分,故除一次,开始计算小数部分
		while(a) {		// 余数不为 0 时不断地除
			decimal[cnt++] = a/b;
			a = (a%b)*10;
		}
		printf("%d", integer);
		if(cnt > 0) {	// 仅当有小数部分时才输出
			printf(".");
			for(int i=0; i<cnt; ++i) {
				printf("%d", decimal[i]);
			}
		}
		printf("\n");
	}
	
	return 0;
}