Answer to Question #186334 in C++ for Anelisiwe Kolweni

Question #186334

Write a function named "reduce" that takes two positive integer arguments, call the "number" and "denim" treats them as the numerator and denominator of a fraction and reduce the fraction.that is to say each of the two arguments will be modified by dividing it by the greatest common division of two integers


1
Expert's answer
2021-04-27T13:07:21-0400
#include <iostream>

using namespace std;


int findGCD(int number1, int number2)
{
    if(number2 == 0)
        return number1;
    return findGCD(number2, number1%number2);
}
int reduce(int& number, int& denim)
{
    int gcd = findGCD(number, denim);


    number/=gcd;
    denim/=gcd;
}


int main()
{
    cout << "Enter numerator: ";
    int number;
    cin >> number;


    cout << "Enter denominator: ";
    int denim;
    cin >> denim;


    reduce(number, denim);


    cout << endl << "Reduced fraction" << endl;
    cout << "numerator: " << number << endl;
    cout << "denominator: " << denim << endl;


    cout << endl << endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
30.04.21, 12:56

Dear Anelisiwe Kolweni, You're welcome. We are glad to be helpful. If you liked our service please press like-button beside answer field. Thank you!

Anelisiwe Kolweni
30.04.21, 11:06

Thank you so much

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS