Python math.gcd()เมธอด
ตัวอย่าง
หาตัวหารร่วมมากของจำนวนเต็มสองจำนวน:
#Import math Library
import math
#find the the greatest
common divisor of the two integers
print (math.gcd(3, 6))
print (math.gcd(6,
12))
print (math.gcd(12, 36))
print (math.gcd(-12, -36))
print (math.gcd(5,
12))
print (math.gcd(10, 0))
print (math.gcd(0, 34))
print (math.gcd(0,
0))
ความหมายและการใช้งาน
วิธี การmath.gcd()
ส่งคืนตัวหารร่วมมากของจำนวนเต็มทั้งสองint1และint2
GCD เป็นตัวหารร่วมที่ใหญ่ที่สุดที่หารตัวเลขโดยไม่เหลือเศษ
GCD เป็นที่รู้จักกันว่าเป็นปัจจัยร่วมสูงสุด (HCF)
เคล็ดลับ: gcd(0,0) คืนค่า 0
ไวยากรณ์
math.gcd(int1, int2)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
int1 | Required. The first integer to find the GCD for |
int2 | Required. The second integer to find the GCD for |
รายละเอียดทางเทคนิค
คืนมูลค่า: | ค่า ที่int แทนตัวหารร่วมมาก (GCD) สำหรับจำนวนเต็มสองตัว |
---|---|
เวอร์ชันหลาม: | 3.5 |