Problem Statement (Simplified):
Print the decimal output of fraction of two given numbers and enclose the repeating part in decimal places in brackets. For example, for a given input of 2 and 3, it’s fraction is 2/3. It’s decimal representation would be 0.6666 where 6 repeats indefinitely, so we cover 6 in brackets and puts output as 0.(6).
Solving Approach :
1) If a fraction is non-repeating, any of it’s remainder will come 0 on repetitive division according to the fundamentals of data structures in c++.
> 1) We know decimal portion repeats itself when a remainder repeats.
> 2) So we’ll check if any remainder repeats and will note it’s last position in quotient.
> 3) After we note it, we finish the process of division as now quotient will repeat itself if it goes on.
> 4) Now print the integer part, a decimal point, non-repeating decimal part, an opening bracket, repeating decimal part and an closing bracket if there is any recurring decimal places.
> 5) If there is no recurring decimal portion, just print the integer part, decimal point and fraction.