#include<stdio.h>
#include<conio.h>
void main()
{
int no1,no2,i,gcd,lcm;
clrscr();
printf("enter 1st number: ");
scanf("%d",&no1);
printf("\nenter 2nd number: ");
scanf("%d",&no2);
for(i=1; i<=no1 && i<=no2; i++)
{
if(no1 %i == 0 && no2 %i == 0)
{
gcd = i;
}
}
printf("\n\ngcd of %d and %d = %d",no1,no2,gcd);
lcm = ( no1 * no2) / gcd;
printf("\n\nlcm of %d and %d = %d",no1,no2,lcm);
getch();
}
/* output:
enter 1st number: 4
enter 2nd number: 6
gcd of 4 and 6 = 2
lcm of 4 and 6 = 12
*/
No comments:
Post a Comment