Created
December 18, 2014 08:10
-
-
Save scratchyourbrain/414e99dcc4db6d32cb4e to your computer and use it in GitHub Desktop.
C Program to Find LCM of two Numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int num1, num2, max; | |
printf("Enter two positive integers: "); | |
scanf("%d %d", &num1, &num2); | |
max=(num1>num2) ? num1 : num2; /* maximum value is stored in variable max */ | |
while(1) /* Always true. */ | |
{ | |
if(max%num1==0 && max%num2==0) | |
{ | |
printf("LCM of %d and %d is %d", num1, num2,max); | |
break; /* while loop terminates. */ | |
} | |
++max; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment