Two whole numbers n and k . Print k decimal digits of 1 / n .

38 Views Asked by At

I have to print these decimal numbers in C++ . But first i need to understand this question mathematically .

1

There are 1 best solutions below

0
On

I suppose $k$ could be arbitrary so we cannot rely on just computing $1/n$ within C++ code and extracting $i$-th decimal by multiplying with $10^i$ and taking $mod\ 10$.
We cannot do this for large $k$ because computer can store just a fixed amount of decimals (if some additional libraries are not used).

The simplest solution would be to just implement long division and print the decimal after each of $k$ steps.