Given a positive integer n, print first k digits after point in value of 1/n. Your program should avoid overflow and floating point arithmetic.
Input: n = 3, k = 3 Output: 333 Input: n = 50, k = 4 Output: 0200
We strongly recommend to minimize the browser and try this yourself first.
Let us consider an example n = 7, k = 3. The first digit of 1/7 is ‘1’, it can be obtained by doing integer value of 10/7. Remainder of 10/7 is 3. Next digit is 4 which can be obtained by taking integer value of 30/7. Remainder of 30/7 is 2. Next digits is 2 which can be obtained by taking integer value of 20/7
This article is contributed by Sachin. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Build Lowest Number by Removing n digits from a given number
- Program to add two polynomials
- Replace all ‘0’ with ‘5’ in an input Integer
- Program to check if a given number is Lucky (all digits are different)
- Carol Number
- Number of Permutations such that no Three Terms forms Increasing Subsequence
- Check if the first and last digit of the smallest number forms a prime
- Print all substring of a number without any conversion
- Complement of a number with any base b
- Check if Decimal representation of an Octal number is divisible by 7