Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

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

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige

Hier ansehen

1 von 2 Anzeige

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

Herunterladen, um offline zu lesen

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

Anzeige
Anzeige

Weitere Verwandte Inhalte

Weitere von lez31palka (20)

Aktuellste (20)

Anzeige

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

×