answersLogoWhite

0


Best Answer

import java.util.Scanner; public class Gcd

{ public static void main(String args[])

{

int temp=0,i; Scanner s=new Scanner(System.in); System.out.println("enter 2 numbers"); int a=s.nextInt(); int b=s.nextInt(); for(i=2;i<=a;i++)

{

if(a%i==0)

{

if(b%i==0)

temp=i;

}//end of if }//end of for System.out.println("Gcd is:"); System.out.println(temp); }//end of main }//end of class

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program in Java to find the greatest common factor?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Basic Math

What is the greatest common factor of 12 and 27?

The greatest common factor (GCF) is often also called the greatest common divisor (GCD) or highest common factor (HCF). Keep in mind that these different terms all refer to the same thing: the largest integer which evenly divides two or more numbers. The greatest common factor of 12 and 27 is 3


How do you write 0.60 in words?

The greatest common factor is the greatest factor that divides both numbers. To find the greatest common factor, first list the prime fators of each number. 18 and 24 share one 2 and one 3 in common. We multiply them to get the GCF, so 2 * 3 = 6 is the GCF of 18 and 24


How do you Write 45 as a product of the GCF and another number?

It is not possible to give a sensible answer to this question. The greatest common factor (GCF) refers to a factor that is COMMON to two or more numbers. You have only one number in the question! There is, therefore no GCF and so answer to the question.


What is the greatest common factor of 54 and 108?

The GCF of 54 and 108 is 54. Since 54 is a factor of 108, it is automatically the GCF. You can also write the factors of 54 and 108, and find the one that's highest: The factors of 54 are 1, 2, 6, 9, 27, and 54 The factors of 108 are 1, 2, 3, 4, 6, 9, 12, 18, 27, 36, 54, and 108 So the GCF (greatest common factor) is 54


How do you find the highest common factor of 4 and 6?

You have to write all the factors of 4, then all of the factors of 6. For example the factors of 4 are: 1,2,4. And the factors of 6 are: 1,2,3,6. Then you find the largest number that is a factor of both! In this case the GCF or greatest common factor would be 2!

Related questions

How can the greatest common factor help you write a fraction in simplest form?

Find the greatest common factor between the numerator and the denominator, then divide the numerator by greatest common factor and then divide denominator by greatest common factor, for a new simplified fraction.


How do you write the answer of the greatest common factor of 16 and 32?

Since 16 is a factor of 32, it is automatically the GCF.


How do you write a fraction in its simplest term?

find the greatest common factor divide by it then you have an answer


How do you Write 7 in prime factorization?

What is the greatest common factor of 525 and 735


Write down the highest common factor of 85 and 155?

Prime factor each number and choose the common factors to multiply.85=5x17155=5x315 is the greatest common factor.


How do you write a program to find the greatest common factor of a set of numbers?

You achieve this by putting all the values in container that allows linear traversal, such as an array. If the array has no numbers at all, the greatest common factor is 0. if the array has one number, the greatest common factor is that number. For arrays with two or more numbers, pop the last two numbers and calculate their greatest common factor, pushing the result back onto the array. Repeat until there is only one number left in the array. That number is the greatest common factor of all the original numbers. To implement this, you will need a function that can return the greatest common factor of any two values. The following shows one way to implement this function: unsigned greatest_common_factor (unsigned a, unsigned b) { while (a!=b) a&gt;b?a-=b:b-=a; return a; }


What is the greatest common factor of 12 and 27?

The greatest common factor (GCF) is often also called the greatest common divisor (GCD) or highest common factor (HCF). Keep in mind that these different terms all refer to the same thing: the largest integer which evenly divides two or more numbers. The greatest common factor of 12 and 27 is 3


Write down the greatest common factor of 80 and 200 in prime factor form?

2 x 2 x 2 x 5 = 40


What are the steps for greatest common factor?

Step 1 : Prime Factorise each number and write in index notation. Step 2 : Multiply the lowest power of each common factor of the given numbers


How do you write 0.60 in words?

The greatest common factor is the greatest factor that divides both numbers. To find the greatest common factor, first list the prime fators of each number. 18 and 24 share one 2 and one 3 in common. We multiply them to get the GCF, so 2 * 3 = 6 is the GCF of 18 and 24


Use the greatest common factor and the distributive property to write equivalent expressions in factored form. 13ab + 15ab?

28ab


Write the prime factorization using exponents of each number then find the greatest common factor of the numbers 12 and 15?

2.2.3 and