1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
using namespace std;
// Function Prototypes
void display();
void output(int, int, int);
// Main Program
int main()
{
int a = 65, b = 15, c = 0, gcd = 0;
display();
output(a, b, a-b);
while ( a && b )
{
if ( a > b )
a = a - b ;
else
b = b - a ;
output(a, b, abs(a-b)) ;
// or, if you want the highest displayed on the left, always:
// output(std::max(a,b), std::min(a,b), abs(a-b)) ;
}
gcd = a ? a : b ;
cout << "\nGCD = " << gcd << "\n\n\n";
}
// Functions
void display()
{
cout << "*************************\n";
cout << "* EUCLID'S ALOGORITHM *\n";
cout << "*************************\n\n";
cout << " A B C \n\n";
}
void output(int a, int b, int c)
{
cout << setw(5) << a << " " << setw(5) << b << " " << setw(5) << c << "\n";
}
|