Computer Science, asked by sharsh2808, 3 months ago

write a program for finding GCD of two numbers​

Answers

Answered by app70
0

Answer:

which language

If python then:-

def compute_hcf(x, y):

# choose the smaller number

if x > y:

smaller = y

else:

smaller = x

for i in range(1, smaller+1):

if((x % i == 0) and (y % i == 0)):

hcf = i

return hcf

num1 = 54

num2 = 24

print("The H.C.F. is", compute_hcf(num1, num2))

Answered by Anonymous
1

\underline{\sf\blue{ᴀɴꜱաɛʀ}}

Program Language : {JAVA}

class Main {

public static void main(String[] args) {

int n1 = 81, n2 = 153;

int gcd = 1;

for (int i = 1; i <= n1 && i <= n2; ++i) {

if (n1 % i == 0 && n2 % i == 0)

gcd = i;

}

System.out.println("GCD of " + n1 +" and " + n2 + " is " + gcd);

}

}

Output :

GCD of 81 and 153 is 9

Similar questions