write a program for finding GCD of two numbers
Answers
Answered by
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
1
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
Math,
2 months ago
Math,
2 months ago
Computer Science,
4 months ago
Political Science,
4 months ago
History,
9 months ago
Math,
9 months ago