O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

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

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

Confira estes a seguir

1 de 2 Anúncio

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

Baixar para ler offline

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

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

Anúncio
Anúncio

Mais Conteúdo rRelacionado

Mais de lez31palka (20)

Mais recentes (20)

Anúncio

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

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

×