loganwol
BAN USER- 5of 5 votes
AnswersWrite a function which, given two integers (a numerator and a denominator), prints the decimal representation of the rational number "numerator/denominator".
- loganwol in United States
Since all rational numbers end with a repeating section, print the repeating section of digits inside parentheses; the decimal printout will be/must be
Example:
1 , 3 = 0.(3)
2 , 4 = 0.5(0)
22, 7 = 3.(142857)
etc..| Report Duplicate | Flag | PURGE
Google SDET Coding
This is the solution I provided first until I was given the example of this -
1, 29 = 0.0344827586206896551724137931034482758620689655172413793103448275862068965517241379310344827586206896551724137931
which would be 0.(03448275862068965517241379310)
notice that will there is a 0, it is not followed by a 3 but instead by a 6. In proposed that instead we find the index of the next 0, take the substring from 0 to index - 1 and then take the substring from index to string1.Length -1 and compare the two. If they were equal we have the string otherwise we repeat the same.
If this is an actual interview question the interviewer needs to be fired! Seriously.
- loganwol September 18, 2014