#include <stdio.h>
#include <conio.h>
void main()
{
int num1, num2, gcd, lcm, remainder, numerator, denominator;
clrscr();
printf(“Enter two numbers\n”);
scanf(“%d %d”, &num1,&num2);
if (num1 > num2)
{
numerator = num1;
denominator = num2;
}
else
{
numerator = num2;
denominator = num1;
}
remainder = num1 % num2;
while(remainder !=0)
{
numerator = denominator;
denominator = remainder;
remainder = numerator % denominator;
}
gcd = denominator;
lcm = num1 * num2 / gcd;
printf(“GCD of %d and %d = %d \n”, num1,num2,gcd);
printf(“LCM of %d and %d = %d \n”, num1,num2,lcm);
} /* End of main() */
/*————————
Output
RUN 1
Enter two numbers
5
15
GCD of 5 and 15 = 5
LCM of 5 and 15 = 15
——————————*/
Not Satisfied ? Just search & get the result
Related posts:
- Sample – Program to enter an integer and output it in the reversed form.
- C program to find and output all the roots of a quadratic equation, for non-zero coefficients.
- C program to simulate a simple calculator to perform arithmetic operations like addition, subtraction,multiplication and division only on integers
- Sample – Program to enter two integers and print the quotient and remainder.
- Write a C program to find the sum of ‘N’ natural numbers
