35) Write a program to input two numbers
and check whether these are Co-Prime
or not? (12=1, 2, 3, 4, 6, 12, 25=1, 5,
25 both have one common factor is 1, so it is Co-Prime number.)
import java.util.*;public class COprime_number{public static void main(String args[ ]){Scanner sc = new Scanner (System.in);System.out.println("Enter two numbers");int a = sc.nextInt();int b = sc.nextInt();int c = 0;for(int i=1;i<=Math.min(a,b)-1;i++){if(a%i==0&&b%i==0)c++;}if(c==1){System.out.println("Entered numbers are CO-PRIME number");}else{System.out.println("Entered numbers are not CO-PRIME number");}}}
No comments:
Post a Comment
if you have any doubts, Please let me know.
Your Truly
Shashank Porwal