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

  • 2
    If $k=9,n=387$ then the output should be $.002583979$ or $(0,0,2,5,8,3,9,7,9 )$. – lulu Oct 2 at 16:38

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.