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
#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;
}
Comments
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!
Thank you so much
Leave a comment