I need help writing a C Program that will read a fraction of the form X/Yfrom th
ID: 3530607 • Letter: I
Question
I need help writing a C Program that will read a fraction of the form X/Yfrom the keyboard, reduce it to its lowest form, and print the result. i.e. if the user enters 6/12 it will print 1/2.
I was wanting the program to prompt the user to enter a fraction, and then read the input from the keyboard in which 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. I want the program to (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. ex. 4/2 will be printed as 2/1.
The algorithm for this is:
int GCD(int a, int b) {
if(b==0)
return a;
else
return GCD(b, a % b);
}