Computer Science, asked by kaur7888mandeep, 6 months ago

write a program to enter two numbers and check whether they are Co prime or not sample input :14,15 sample output :they are co-prime(don't ask invigilator about coprime​

Answers

Answered by anindyaadhikari13
5

Question:-

Write a program go enter two numbers and check whether they are co prime or not.

Program:-

Two numbers are said to be co prime if their HCF is 1. In other words, the numbers that have highest common factors as 1 are called co prime numbers.

So, here is your program.

In Java.

import java.util.*;

class Co_Prime

{

public static void main(String args[])

{

Scanner sc = new Scanner(System.in);

System.out.print("Enter the first number: ");

int a=sc.nextInt();

System.out.print("Enter the second number: ");

int b=sc.nextInt();

while(b != 0)

{

int r =a%b;

a=b;

b=r;

}

if(a==1)

System.out.println("Co Prime. ");

else

System.out.println("Not Co Prime. ");

}

}

Similar questions