# Answer to Question #17764 in C++ for apoorva

Question #17764

Write a C++ function to find at least common divisor of two integers.

Expert's answer

#include <iostream>

using namespace std;

main()

{int a,b,i=2,k=-1;

cout<<"Enter a: ";

cin>>a;

cout<<"Enter b: ";

cin>>b;

while(k==-1 && i<(a+b)){

if(a%i==0 && b%i==0)

& k=i;

i++;

}

if(k!=-1)

cout<<"Least common divisor:& "<<k<<"\n";

else cout<<"No common divisor\n";

system("pause");

& }

using namespace std;

main()

{int a,b,i=2,k=-1;

cout<<"Enter a: ";

cin>>a;

cout<<"Enter b: ";

cin>>b;

while(k==-1 && i<(a+b)){

if(a%i==0 && b%i==0)

& k=i;

i++;

}

if(k!=-1)

cout<<"Least common divisor:& "<<k<<"\n";

else cout<<"No common divisor\n";

system("pause");

& }

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment