PROGRAM : 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);
//Assign Numbers to Temporary Variables
temp1=num1;
temp2=num2;
//To Find Gcd
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;
}
OUTPUT :
No comments:
Post a Comment