177k views
3 votes
Write a program convert a repeating decimal to a fraction. Let N be the number and let m be the

number of digits in the repeating block and let x be the number of non-repeating digits. For example,
0.01838383... has 2 digits in the repeating block, whereas 0.018333... has only 1. The first has 2
non-repeating digits and the second has 3. Some examples:
• When the repeating block starts at the decimal point: Setting N equal to the given value, multiply
both sides of the equation by 10m. Then subtract N from both sides. You will end up with an equation
which you can solve for N as a fractional value.

N = 0.33333...

Multiply both sides by 10m (m = 1) 10N = 3.33333...
Subtract N from both sides N = 0.33333...
9N = 3
N = 3/9 = 1/3

• When the repeating block does not start at the decimal point: Setting N equal to the given value,
multiply both sides of the equation by 10n+x. Then multiply both sides of the original equation by 10x and
subtract the results. You will end up with an equation which you can solve for N as a fractional value.

N = 0.01838383...

Multiply both sides by 10m+x (m + x = 4) 10000N = 183.838383...
Multiply both sides by 10x (x = 2) 100N = 1.838383...
Subtract the two equations 9900N = 182
N = 182/9900 = 91/4950

Input from the keyboard a positive repeating decimal. Assume the integer part of the number will
always be zero. Output to the screen each decimal number in fractional form reduced to lowest terms.
Finally, the program should ask if the user wants to run the program again (Check case). to the sample
output below.

Updated September 20, 2022 COSC 2425 F22
2

Sample Run:
Enter the decimal: 0.222

Fraction: 2/9

Run again (Y/N): y

Enter the decimal: 0.12555

Fraction: 113/900

Run again (Y/N): N


Name the application: DecToFracXX.cpp or DecToFracXX.java, where XX are your initials.

1 Answer

4 votes

Final answer:

A program to convert repeating decimals to fractions in simplified form involves using mathematical principles and equations, asking users for input, and providing output in a fraction format.

Step-by-step explanation:

The correct answer involves writing a program that converts a repeating decimal to a fraction. To tackle this problem, you'll leverage mathematical operations, specifically by creating equations that model the relationship between repeating decimals and their fraction equivalents. The program will then simplify the generated fraction to its lowest terms and display the result to the user. In a typical implementation of such a program, like DecToFracXX.cpp or DecToFracXX.java, the user will input a repeating decimal, and the program will output the simplest fractional form. It typically requires manipulation of decimal places and simplification of fractions.

The algorithm incorporates multiplication by powers of ten and subtraction of equations to isolate the repeating portion of the decimal. By managing the decimal places and utilizing variables such as m for the number of digits in the repeating block and x for the number of non-repeating digits, the fraction can be accurately determined.

User Mingle Li
by
7.7k points

No related questions found