อันดับแรก ให้เราเรียนรู้วิธีหาปัจจัยร่วมสูงสุด (HCF)
ปัจจัยร่วมสูงสุด (HCF)
จำนวนที่มากที่สุดหารแต่ละตัวเลขสองตัวหรือมากกว่านั้นเรียกว่า HCF หรือปัจจัยร่วมสูงสุด เรียกอีกอย่างว่า Greatest Common Measure (GCM) และ Greatest Common Divisor (GCD)
ตัวอย่างเช่น
HCF ของ 12 และ 16 คืออะไร
Factors of 12 = 1, 2, 3, 4, 6,12. Factors of 16=1,2,4,8,16
ปัจจัยร่วมสูงสุด (H.C.F) ของ 12 และ 16 =4
ตัวคูณร่วมน้อย (LCM)
สำหรับจำนวนเต็ม x และ y สองจำนวน แสดงแทน LCM(x,y) เป็นจำนวนเต็มบวกที่เล็กที่สุดที่หารด้วย x และ y ลงตัว
ตัวอย่างเช่น
LCM(2,3) = 6 and LCM(6,10) = 30.
ตัวอย่าง
#include <stdio.h>
int main() {
int num1, num2, x, y, temp, gcd, lcm;
printf("Enter two integers\n");
scanf("%d%d", &x, &y);
num1 = x;
num2 = y;
while (num2 != 0) {
temp = num2;
num2 = num1 % num2;
num1 = temp;
}
gcd = num1;
lcm = (x*y)/gcd;
printf("GCD of %d and %d = %d\n", x, y, gcd);
printf("LCM of %d and %d = %d\n", x, y, lcm);
return 0;
} ผลลัพธ์
เมื่อดำเนินการ คุณจะได้รับผลลัพธ์ต่อไปนี้ -
Run 1: Enter two integers 6 12 GCD of 6 and 12 = 6 LCM of 6 and 12 = 12 Run 2: Enter two integers 24 36 GCD of 24 and 36 = 12 LCM of 24 and 36 = 72