C Program for loop: "HCF and LCM of Two number using for loop" with output

 #include <stdio.h>

int main() { int num1, num2, i, hcf, lcm; // Input two numbers from the user printf("Enter first number: "); scanf("%d", &num1); printf("Enter second number: "); scanf("%d", &num2); // Find the HCF (GCD) of the two numbers for (i = 1; i <= num1 && i <= num2; i++) { if (num1 % i == 0 && num2 % i == 0) { hcf = i; } } // Calculate LCM using the formula: LCM = (num1 * num2) / HCF lcm = (num1 * num2) / hcf; // Display the HCF and LCM printf("HCF of %d and %d is %d\n", num1, num2, hcf); printf("LCM of %d and %d is %d\n", num1, num2, lcm); return 0; }






Enter first number: 24 Enter second number: 36 HCF of 24 and 36 is 12 LCM of 24 and 36 is 72

Comments

Popular posts from this blog

How to shoot good video using mobile