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...

# 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

Related

C Programs 1255065389462922151

Post a Comment

emo-but-icon

item