Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* program to find GCD using euclids algorithm */
- #include<iostream>
- using namespace std;
- int main()
- {
- int num2,num1,quotient,temp;
- cout<<"\n ENTER 2 NUMBERS :";
- cin>>num1>>num2;
- if(num1>num2)
- {
- do
- {
- // calculating quotient
- quotient=num1/num2;
- temp=num2;
- num2=num1-quotient*num2;
- num1=temp;
- }while(num2!=0);
- cout<<"\nThe GCD of 2 numbers is: "<<num1;
- }
- else
- {
- do
- {
- // calculating quotient
- quotient=num2/num1;
- temp=num1;
- num1=num2-quotient*num1;
- num2=temp;
- }while(num1!=0);
- cout<<"\n the GCD of 2 numbers is: "<<num2;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment