Write a program using C Language that will read a fraction of the form X/Y from
ID: 3529420 • Letter: W
Question
Write a program using C Language that will read a fraction of the form X/Y from the keyboard, reduce it to its lowest form, and print the result. i.e. if the user enters 6/12 your program will print 1/2.
The program must prompt the user to enter a fraction, and then read the input from the keyboard. This information may not be read from the command line as part of the program invocation.
The program should be enclosed in a loop that asks the user if she/he wants to reduce another fraction. Thus, the user should be able to reduce an unlimited number of fractions without re-running the program.
The program must validate user input, and if an incorrect fraction is entered, print a helpful error message and allow the user to re-enter a fraction.
The numerator and denominator are 32 bit signed integers.
The output must be a fraction of the form X/Y. [ 4/2 will be printed as 2/1.
Sample Output:
The best way to reduce a fraction is by using Euclid's algorithm to find the GCD (greatest common divisor). The algorithm for this is:
Explanation / Answer
There are some things I added which I wasn't sure if you were allowed to use. There's always room for improvement. I also didn't implement the command line properties that it asked for. The actual reduction is done tho, use what I have as a reference I guess. You'll have to add a check for dividing by zero as well. Best of luck finishing up the rest of it. http://pastebin.com/JGJtcVMr
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.