Friday, October 14, 2011

Write a C program to find the GCD and LCM of two given integers, and output the results.

#include
main()
{
int a,b,gcd,lcm,r,m=0,i;
printf("Enter two numbers you want :>\n"); //user input
scanf("%d %d",&a,&b);
if (a m=a;
else
m=b;
for (i=1;i<=m;i++)
{
if (a%i==0&&b%i==0)
gcd=i;
}
r=a*b;
lcm=r/gcd;
printf("GCD of the given two numbers= %d",gcd); //printing GCD of given two numbers
printf("\nLCM of the given two numbers= %d\n",lcm); //printing LCM of given two numbers

}

No comments:

Post a Comment