#include using namespace std; //find the greatest common denominator using //Euclid's algorithm int gcd(int a, int b) { int t; while(b != 0) { t = b; b = a % t; a = t; } return a; } int main(void) { int n1, d1; //first fraction int n2, d2; //second fraction int rn, rd; //result int g; //greatest common denominator //get the first fraction cout << "Numerator 1: "; cin >> n1; cout << "Denomenator 1: "; cin >> d1; //get the second fraction cout << "Numerator 2: "; cin >> n2; cout << "Denomenator 2: "; cin >> d2; //get a common denominator rd = d1 * d2; //convert the fractions n1 = n1 * d2; n2 = n2 * d1; //add numerators rn = n1 + n2; //simplify (gcd) g = gcd(rn, rd); rn = rn/g; rd = rd/g; //display the fraction cout << "Result: " << rn << "/" << rd << endl; return 0; }