write a program to display the LCM of three numbers
Answers
Answered by
0
int main()
{
int num1, num2,num3, max,ans;
printf("Enter three positive integers: ");
scanf("%d %d %d", &num1, &num2,&num3);
max=(num1>num2) ? num1 : num2; /* maximum value is stored in variable max */ while(1) /* Always true. */
{
if(max%num1==0 && max%num2==0)
{
break; /* while loop terminates. */
}
++max;
}
ans=(max>num3) ? max : num3; /* maximum value is stored in variable ans */
while(1) /* Always true. */
{
if(ans%num1==0 && ans%num2==0)
{
printf("LCM of %d and %d is %d", max, num3,ans);
break; /* while loop terminates. */
}
++ans;
}
return 0;
}
{
int num1, num2,num3, max,ans;
printf("Enter three positive integers: ");
scanf("%d %d %d", &num1, &num2,&num3);
max=(num1>num2) ? num1 : num2; /* maximum value is stored in variable max */ while(1) /* Always true. */
{
if(max%num1==0 && max%num2==0)
{
break; /* while loop terminates. */
}
++max;
}
ans=(max>num3) ? max : num3; /* maximum value is stored in variable ans */
while(1) /* Always true. */
{
if(ans%num1==0 && ans%num2==0)
{
printf("LCM of %d and %d is %d", max, num3,ans);
break; /* while loop terminates. */
}
++ans;
}
return 0;
}
Snitchseeker:
Which programming language
Similar questions