C Program to find the GCD and LCM of two numbers.

 #include<stdio.h>

main()

{

int lcm,gcd,a,b,prod;

clrscr();

printf("\nEnter two values\n");

scanf("%d%d",&a,&b);

prod=a*b;

while(a!=b)

{

if(a>b)

{

a=a-b;

}

else if(b>a)

{

b=b-a;

}

}

gcd=a;

lcm=prod/gcd;

printf("\nLCM= %d and GCD= %d",lcm,gcd);

getch();

}




Output:

  1. Enter two values

10 15


LCM= 30 and GCD= 5



  1. Enter two values

20

30


LCM= 60 and GCD= 10




Post a Comment

Previous Post Next Post