Pagi ini saya akan membagikan tentang Greatest Common Divisor pada pemrograman java, . .
Selamat mencoba, .
import java.util.Scanner;
public class GreatestCommonDivisor {
public static void main(String[] iriahus) {
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);
System.out.print("Enter the first integer: ");
int a = s.nextInt();
System.out.print("Enter the second integer: ");
int b = s.nextInt();
int gcd = 1;
int d = 2;
for (d = 2; d <= a || d <= b; d++) {
if (a % d == 0 && b % d == 0) {
gcd = d;
}
}
System.out.println("The GCD of " + a + " and " + b + " is " + gcd);
}
}
Semoga bermanfaat, . .
0 Response to "Greatest Common Divisor"
Post a Comment