Program to find LCM
and GCD
of the given two numbers
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int n1, n2, prod, gcd, lcm;
clrscr();
printf("Enter the two numbers : ");
scanf("%d %d", &n1, &n2);
prod = n1 * n2;
while(n1 != n2)
{
if(n1 > n2)
n1 = n1  n2;
if(n2 > n1)
n2 = n2  n1;
}
gcd = n1;
lcm = prod / gcd;
printf("\nThe GCD is : %d", gcd);
printf("\n\nThe LCM is : %d", lcm);
getch();
}
Output:
Enter the two numbers : 10 8
The GCD is : 2
The LCM is : 40

UpdatedDec 30, 2019

Views9,748
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order