Write A Program for calculating LCM & GCD
# include<stdio.h> #include<conio.h> void main ( ) { int x, y, lcm, m, i, gcd; printf (“enter x, y values”); sca...
https://www.computersprofessor.com/2016/06/write-program-for-calculating-lcm-gcd.html?m=0
# include<stdio.h>
#include<conio.h>
void main ( )
{
int x, y, lcm, m, i, gcd;
printf (“enter x, y values”);
scanf("%d%d",&x,&y);
m = ( x < y) ? x : y;
for ( i = 1 ; i < m; i+ +)
{
if (x%i = = 0) && ( y%i = = 0))
gcd = i;
}
printf("\n gcd=%d",gcd);
lcm = ( x * y) /i;
printf ( “ \n lcm = %d,” lcm );
getch ( );
}
Out Put:
enter x, y values 4 12
gcd = 4
lcm = 12