Solution 1
Video Link
Click here
//C program to find LCM of two numbers
#include <stdio.h>
int main()
{
int Num1, Num2, max_Value;
printf("Please Enter two integer Values \n");
scanf("%d %d", &Num1, &Num2);
max_Value = (Num1 > Num2)? Num1 : Num2;
while(1) //Alway True
{
if(max_Value % Num1 == 0 && max_Value % Num2 == 0)
{
printf("LCM of %d and %d = %d", Num1, Num2, max_Value);
break;
}
++max_Value;
}
return 0;
}
Solution 2
#include<stdio.h>
main()
{
int num1,num2,gcd,temp,a,b,lcm;
printf("Enter first number?");
scanf("%d",&num1);
printf("Enter second number?");
scanf("%d",&num2);
a=num1;
b=num2;
for(;b>0;)
{
temp=b;
b=a%b;
a=temp;
}
gcd=a;
lcm=(num1*num2)/gcd;
printf("\n Least common divisor of %d and %d= %d",num1,num2,lcm);
return 0;
}
Solution-3
#include <stdio.h>
int main()
{
int a, b, x;
printf("Enter the first integer number: \n");
scanf("%d", &a);
printf("Enter the second integer number: \n");
scanf("%d", &b);
if(a>b){
x=a;
}
else if(b>a){
x=b;
}
again:
if((x%a==0)&&(x%b==0)){
printf("LCM is %d \n", x);
}
else{
x=x+1;
goto again;
}
return 0;
}
0 comments:
Post a Comment