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");

& }

Learn more about our help with Assignments: C++

## Comments

## Leave a comment