GCD của hai số trong Python sử dụng cho vòng lặp. Trong bài viết này, bạn sẽ tìm hiểu cách & nbsp; tìm GCD của hai số trong Python sử dụng cho vòng lặp.
GCD & NBSP; của hai số là gì?
GCD là số nguyên lớn nhất của hai số nguyên dương & nbsp; có thể chia chính xác & nbsp; cả hai số mà không còn A & nbsp; phần còn lại.GCD is the largest integer number of two positive integer numbers that can exactly divide both numbers without remaining a remainder.
GCD của hai số trong Python sử dụng trong khi vòng lặp
# GCD of Two Numbers in Python using While loop
p, q = None, None
# p & q - denotes the two positive numbers
print ["-----Enter the two positive integer numbers-----"]
p = int [input []]
q = int [input []]
while p != q:
if p > q:
p -= q
else:
q -= p
print ["\nThe GCD number is: ", p]
Chạy chương trình
Đầu ra
-----Enter the two positive integer numbers-----
160
70
The GCD number is: 10
GCD của hai số trong Python sử dụng cho vòng lặp
# GCD of Two Numbers in Python using For loop
p, q, g = None, None, None
# p & q - denotes the two positive numbers
print ["-----Enter the two positive integer numbers-----"]
p = int [input []]
q = int [input []]
for i in range [1, p + 1]:
if i B: # Xác định điều kiện IF ..