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.
- Minimum positive integer value possible of X for given A and B in X = P*A + Q*B
- Minimum positive integer to divide a number such that the result is an odd
- Count positive integers with 0 as a digit and maximum 'd' digits
- Count even and odd digits in an Integer
- Program to count digits in an integer (3 Different Methods)
- Reverse digits of an integer with overflow handled
- Print numbers with digits 0 and 1 only such that their sum is N
- Print all numbers less than N with at-most 2 unique digits
- Print last k digits of a^b (a raised to power b)
- Print all possible words from phone digits
- Print individual digits as words without using if or switch
- Print all n-digit numbers whose sum of digits equals to given sum
- Print a number containing K digits with digital root D
- Print all n-digit numbers with absolute difference between sum of even and odd digits is 1
- Print prime numbers with prime sum of digits in an array