Write a C++ program to ask the user to enter two integers a and b and find the gcd ( a,b ) using The Euclidean Algorithm.
Write a C++ program to ask the user to enter two integers a and b and find the gcd ( a,b ) using The Euclidean Algorithm.
Solution
Answer:
#include<iostream>
#include<cstdlib>
using namespace std;
int greatestcommondivisor(int num1,int num2)
{
if((num1>=num2)&&((num1%num2)==0))
return(num2);
else
greatestcommondivisor(num2,(num1%num2));
}
int main()
{
int num1,num2,output;
cout<<\"Enter first integer number:\";
cin>>num1;
cout<<\"Enter second number:\";
cin>>num2;
output=greatestcommondivisor(num1,num2);
cout<<\"gcd of \"<<num1<<\" and \"<<num2<<\" is \"<<output;
return 0;
}
.