# 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() ;
}
RUN 1 :
~~~~~~~
Enter the two numbers : 10 8
The GCD is : 2
The LCM is : 40
# 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() ;
}
RUN 1 :
~~~~~~~
Enter the two numbers : 10 8
The GCD is : 2
The LCM is : 40
No comments:
Post a Comment