source file name: gcdlcm.C
#include<stdio.h>
void main()
{
int a,b,t;
int gcd,lcm;
clrscr();
printf("\n enter two numbers(first no less than second no) : ");
scanf("%d%d",&a,&b);
t=a;
while(a>1)
{
if(a%t==0 && b%t==0)
{
gcd=t;
break;
}
else
t--;
}
lcm=a*b/gcd;
printf("\n GCD= %d and LCM= %d ",gcd,lcm);
getch();
}
output:
0 Comments
Post a Comment