write the progaram by using concept of class to find the greatest diviser of two number
Share
write the progaram by using concept of class to find the greatest diviser of two number
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Verified answer
Answer:
PLEASE MARK ME AS BRAINLIST
Explanation:
{ public static void main(String[] args) { //x and y are the numbers to find the GCF int x = 12, y = 8, gcd = 1; //running loop form 1 to the smallest of both numbers for(int i = 1; i <= x && i <= y; i++) { //returns true if both conditions are satisfied if(x%i==0 && y%i==0) //storing the variable i in the variable gcd gcd = i; } //prints the gcd System.out.printf("GCD of %d and %d is: %d", x, y, gcd); } }
Answer:
Using Modulo Operator
public class FindGCDExample6.
{
public static void main(String[] args)
{
int a = 112, b = 543;
System.out.println("GCD of " + a +" and " + b + " is " + findGCD(a, b));
}
//recursive function to return gcd of a and b.