Run ❯
Get your
own
website
×
Change Orientation
Change Theme, Dark/Light
Go to Spaces
Python
C
Java
def gcd_division(a, b): while b != 0: remainder = a % b print(f"{a} = {a//b} * {b} + {remainder}") a = b b = remainder return a a = 120 b = 25 print("The Euclidean algorithm using division:\n") print(f"The GCD of {a} and {b} is: {gcd_division(a, b)}") #Python
#include
int gcdDivision(int a, int b) { while (b != 0) { int remainder = a % b; printf("%d = %d * %d + %d\n", a, a / b, b, remainder); a = b; b = remainder; } return a; } int main() { int a = 120; int b = 25; printf("The Euclidean algorithm using division:\n\n"); printf("The GCD of %d and %d is: %d\n", a, b, gcdDivision(a, b)); return 0; } //C
public class Main { public static int gcdDivision(int a, int b) { while (b != 0) { int remainder = a % b; System.out.println(a + " = " + (a / b) + " * " + b + " + " + remainder); a = b; b = remainder; } return a; } public static void main(String[] args) { int a = 120; int b = 25; System.out.println("The Euclidean algorithm using division:\n"); System.out.println("The GCD of " + a + " and " + b + " is: " + gcdDivision(a, b)); } } //Java
Python result:
C result:
Java result:
The Euclidean algorithm using division:
120 = 4 * 25 + 20
25 = 1 * 20 + 5
20 = 4 * 5 + 0
The GCD of 120 and 25 is: 5
The Euclidean algorithm using division:
120 = 4 * 25 + 20
25 = 1 * 20 + 5
20 = 4 * 5 + 0
The GCD of 120 and 25 is: 5
The Euclidean algorithm using division:
120 = 4 * 25 + 20
25 = 1 * 20 + 5
20 = 4 * 5 + 0
The GCD of 120 and 25 is: 5