Given three integers P, Q and N where P < Q, the task is to compute the fraction value of P / Q and find the Nth digit after the decimal.
Input: P = 1, Q = 2, N = 1
(1 / 2) = 0.5 and 5 is the first digit after the decimal.
Input: P = 5, Q = 6, N = 5
(5 / 6) = 0.833333333…
Approach: Initialize an integer variable res that stores the resultant Nth digit. Now, while N > 0 do the following:
- Decrement N by 1.
- To compute the digit, update the value P = P * 10.
- Compute res = P / Q and update P = P % Q.
Finally, print the res.
Below is the implementation of the above approach:
- Largest proper fraction with sum of numerator and denominator equal to a given number
- Find ΔX which is added to numerator and denominator both of fraction (a/b) to convert it to another fraction (c/d)
- First occurrence of a digit in a given fraction
- Find Last Digit of a^b for Large Numbers
- Sum of all proper divisors of natural numbers in an array
- Sum of product of proper divisors of all Numbers lying in range [L, R]
- Find the highest occurring digit in prime numbers in a range
- Represent the fraction of two numbers in the string format
- Count of Numbers in Range where first digit is equal to last digit of the number
- Find Recurring Sequence in a Fraction
- Count n digit numbers not having a particular digit
- Find the remainder when First digit of a number is divided by its Last digit
- Count numbers having 0 as a digit
- Count of all N digit numbers such that num + Rev(num) = 10^N - 1
- Numbers having difference with digit sum more than s
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.