C Program to Find LCM of two Numbers Examples on different ways to calculate the LCM (Lowest Common Multiple) of two integers using loops and decision making statements. To understand this example, you should have the knowledge of following C programming topics: C Programming Operators C if...else Statement C Programming while and do...while Loop The LCM of two integers n1 and n2 is the smallest positive integer that is perfectly divisible by both n1 and n2 (without a remainder). For example: the LCM of 72 and 120 is 360. Example #1: LCM using while Loop and if Statement #include <stdio.h> int main () { int n1 , n2 , minMultiple ; printf ( "Enter two positive integers: " ); scanf ( "%d %d" , & n1 , & n2 ); // maximum number between n1 and n2 is stored in minMultiple minMultiple = ( n1 > n2 ) ? n1 : n2 ; // Always true while ( 1 ) ...
Comments
Post a Comment