m2skills

gcdEuclid c++

May 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. /* program to find GCD using euclids algorithm */
  2.  
  3. #include<iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int num2,num1,quotient,temp;
  10.     cout<<"\n ENTER 2 NUMBERS :";
  11.     cin>>num1>>num2;
  12.     if(num1>num2)
  13.     {
  14.         do
  15.         {
  16.             // calculating quotient
  17.             quotient=num1/num2;
  18.             temp=num2;
  19.             num2=num1-quotient*num2;
  20.             num1=temp;
  21.         }while(num2!=0);
  22.         cout<<"\nThe GCD of 2 numbers is: "<<num1;
  23.     }
  24.     else
  25.     {
  26.         do
  27.         {
  28.             // calculating quotient
  29.             quotient=num2/num1;
  30.             temp=num1;
  31.             num1=num2-quotient*num1;
  32.             num2=temp;
  33.         }while(num1!=0);
  34.         cout<<"\n the GCD of 2 numbers is: "<<num2;
  35.     }
  36.     return 0;
  37. }
Add Comment
Please, Sign In to add comment