axyd

Lab 6, part 3

May 1st, 2016
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void GCD(int, int, int&);
  5.  
  6. int main(){
  7.     char again = 'y';
  8.     while (again == 'y' || again == 'Y'){
  9.         int usr1, usr2, fetch = 0;
  10.         cout << "GCD finder, enter 2 numbers: ";
  11.         cin >> usr1 >> usr2;
  12.  
  13.         GCD(usr1, usr2, fetch);
  14.         cout << "The GCD is: " << fetch << endl << endl;
  15.  
  16.         cout << "do you want to rerun(y|Y)? ";
  17.         cin >> again;
  18.     }
  19. }
  20.  
  21. void GCD(int i1, int i2, int& out){
  22.     out = 0; //reinitialize
  23.  
  24.     int c = i1 % i2;
  25.     while (c != 0)
  26.     {
  27.         i1 = i2;
  28.         i2 = c;
  29.         c = i1 % i2;
  30.     }
  31.     out = i2;
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment