求小数的某一位(高精度运算)

描述

分数a/b化为小数后,小数点后第n位的数字是多少?

其中0 < a < b < 100,1≤n≤10000。

格式

输入格式

三个正整数a,b,n,相邻两个数之间用单个空格隔开。

输出格式

一个数字

样例

输入样例

1 2 1

输出样例

5

限制

时间限制: 1000 ms

内存限制: 65536 KB

思路:模拟除法

#include <iostream>
#include <math.h>
using namespace std;

int main ()
{
	int a, b, n , ans=1, temp=1;
	scanf ("%d %d %d", &a, &b, &n);
	for (int i=0; i<n; i++) {    //模拟除法
		a = a * 10;
		ans = a / b;
		a = a % b;
	}
	printf ("%d", ans);
	return 0;
}
发布了89 篇原创文章 · 获赞 77 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/wodemaoheise/article/details/104633333
今日推荐