From 46e58ba743989d3532816b1303cb935f73fdb247 Mon Sep 17 00:00:00 2001 From: Aman Mishra <72151791+AmanMishra04@users.noreply.github.com> Date: Sat, 8 Oct 2022 23:52:46 +0530 Subject: [PATCH] Create LCMoftwoNumbers.c Program to find the LCM of two numbers using a while loop. --- LCMoftwoNumbers.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 LCMoftwoNumbers.c diff --git a/LCMoftwoNumbers.c b/LCMoftwoNumbers.c new file mode 100644 index 0000000..a50c4aa --- /dev/null +++ b/LCMoftwoNumbers.c @@ -0,0 +1,18 @@ +#include +int main() { + int num1, num2, max; + printf("Enter two positive integers: "); + scanf("%d %d", &num1, &num2); + + // greater number between num1 and num2 is stored in max + max = (num1 > num2) ? num1 : num2; + + while (1) { + if (max % num1 == 0 && max % num2 == 0) { + printf("LCM of input numbers %d and %d is %d.", num1, num2, max); + break; + } + ++max; + } + return 0; +}