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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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 two numbers with sum N such that neither of them contains digit K
- Find two numbers whose sum is N and does not contain any digit as K
- Find Last Digit of a^b for Large Numbers
- Find two numbers made up of a given digit such that their difference is divisible by N
- Sum of all proper divisors of natural numbers in an array
- Find the highest occurring digit in prime numbers in a range
- Sum of product of proper divisors of all Numbers lying in range [L, R]
- 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
- Count numbers in a range with digit sum divisible by K having first and last digit different
- Find Recurring Sequence in a Fraction
- Find N fractions that sum upto a given fraction N/D
- Find the remainder when First digit of a number is divided by its Last digit
- Count n digit numbers not having a particular digit
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers
- Count of all N digit numbers such that num + Rev(num) = 10^N - 1
- Count numbers having 0 as a digit
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.