C Online Compiler
Example: C Program to Find LCM of Two Numbers using For loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to Find LCM of Two Numbers using For loop #include <stdio.h> int main() { int p, q, i, g, x; // p & q - To store the two positive numbers // x - To store the LCM number // g - To store the GCD printf("-----Enter the two positive integer numbers-----\n"); scanf("%d %d", &p, &q); for (i = 1; i <= p && i <= q; ++i) { if (p % i == 0 && q % i == 0) { g = i; } } x = (p * q) / g; printf("\nThe LCM of two positive numbers %d and %d is %d.\n", p, q, x); return 0; }
80 110
Output
Clear
ADVERTISEMENTS