Seu SlideShare está sendo baixado. ×

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio

1 de 2 Anúncio

# Write a C++ program to ask the user to enter two integers a and b and.docx

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
#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;
}
.

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
#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;
}
.

Anúncio
Anúncio