write a program in Java to check whether the number entered is a coprime number or not
Answers
class GFG
{
static int __gcd(int a, int b)
{
if (a == 0 || b == 0)
return 0;
if (a == b)
return a;
if (a > b)
return __gcd(a-b, b);
return __gcd(a, b-a);
}
static void coprime(int a, int b)
{
if ( __gcd(a, b) == 1)
System.out.println("Co-Prime");
else
System.out.println("Not Co-Prime");
}
public static void main (String[] args)
{
int a = 5, b = 6;
coprime(a, b);
a = 8; b = 16;
coprime(a, b);
}
}
-------------------*--------------------------
You modify a and b value.
Mark Brainlieast
import java.util.*;
public class CoPrime
{
public static void main (String args []) {
Scanner in = new Scanner(System.in); int n, s, a , b , c = 0; System.out.println("enter the two numbers:");
a = in.nextInt();
b = in.nextInt();
s = Math.min(a,b);
for(n = 1; n <= s; n++)
{
if(a%n==0 && b%n==0)
{
c++
}
}
if(c==1)
{
System.out.println("These numbers are co-prime numbers");
}
else
{
System.out.println("These are not a prime numbers");
}
}
}