WRITE ONE C PROGRAM TO ACHIEVE THE FOLLOWING Write a program
WRITE ONE C++ PROGRAM TO ACHIEVE THE FOLLOWING:
Write a program that takes two integer numbers and checks whether they are co-prime (co-prime: two integers a and b are said to be co-prime if the only positive integer that divides both of them is 1) or not.
sample input: 15 13
sample output: yes
sample input: 20 15
sample output: no
Solution
If the greatest common divisor of both these numbers is 1. Hence, we write a function to check if the gdc is 1 or not. Here is the code:
#include <iostream>
using namespace std;
int gcd(int a, int b)
{
int x;
while(1)
{
x = a%b;
if(x==0)
return b;
a = b;
b = x;
}
}
int main()
{
int a,b,g;
cout<<\"Enter Values\"<<endl;
cin>>a>>b;
g=gcd(a,b);
if(g==1)
{
cout<<\"YES\"<<endl;
}
else
{
cout<<\"NO\"<<endl;
}
return 0;
}
