"
Question: Find the GCD and LCM of two numbers taken input from the user.
Solution:
#include<stdio.h>
int main()
{
int a,b,x,y,rem,gcd,lcm;
printf("Enter your desire two numbers : \n");
scanf("%d %d",&a,&b);
x=a;
y=b;
rem = a%b;
while(rem!=0){
a = b ;
b = rem ;
rem = a % b;
}
gcd = b;
lcm = (x*y)/gcd;
printf("GCD = %d\nLCM = %d\n",gcd,lcm);
return 0;
}
3/related/default
Post a Comment
0Comments