Tuesday, 5 September 2017

C-Program to Print GCD and LCM



#include<stdio.h>
 
int main()
{
int num1,num2,temp1,temp2,gcd,lcm,x;
printf("Enter number 1\n");
scanf("%d",&num1);
printf("Enter number 2\n");
scanf("%d",&num2); 
temp1=num1;
temp2=num2;
 
while(temp2!=0)
{
x=temp2;
temp2=temp1%temp2;
temp1=x;
}
 
gcd=temp1;
lcm=(num1*num2)/gcd;
printf("gcd is %d\n",gcd);
printf("Lcm is %d\n",lcm);
return 0; 
}

No comments:

Post a Comment