Skip to content

Instantly share code, notes, and snippets.

@scratchyourbrain
Created December 18, 2014 08:10
Show Gist options
  • Save scratchyourbrain/414e99dcc4db6d32cb4e to your computer and use it in GitHub Desktop.
Save scratchyourbrain/414e99dcc4db6d32cb4e to your computer and use it in GitHub Desktop.
C Program to Find LCM of two Numbers
#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