exercise1

# exercise1 - n else cout<< endl<<"...

This preview shows page 1. Sign up to view the full content.

#include <iostream> using namespace std; u // Function to return the pgcd of two numbers / int pgcd(int n1, int n2) { if(n2==0) return n1; return pgcd(n2, n1%n2); } // Function to reduce and output several fractions / void ConvertToLowestTerms(int Numerator, int Denominator) { int n = Numerator; int d = Denominator; if(Numerator!=0){ n = n / pgcd(Numerator,Denominator); d = d / pgcd(Numerator,Denominator); } if(Numerator == 0 || d == 1) cout << endl << " Fraction : " << Numerator << "/" << Denominator << " = " << n << endl << endl;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n else cout << endl << " Fraction : " << Numerator << "/" << Denominator << " = " << n << "/" << d << endl << endl; n } int main () { int Numerator, Denominator; cout << "Choose the Numerator : "; cin >> Numerator; cout << endl << "Choose the Denominator : "; cin >> Denominator; if(Denominator == 0) cout << endl << "It is impossible. " << endl; else { cout << endl << " PGCD : " << pgcd (Numerator,Denominator) << endl; ConvertToLowestTerms(Numerator, Denominator); } }...
View Full Document

## This note was uploaded on 11/01/2009 for the course AV 244 taught by Professor Dub during the Spring '09 term at ECE.

Ask a homework question - tutors are online