Computer Science, asked by devpxs, 4 months ago

Write a program to input 3 numbers of integer type and print their LCM.

Answers

Answered by akankshakamble6
1

Answer:

If you can write a program to find LCM of two numbers. Then you can very easily write a program to find LCM of three numbers also , cause lcm(a,b,c)=lcm(a,lcm(b,c)) .

So here's your c program to find LCM of three numbers.

#include<stdio.h>

int lcm(int,int);

int main(){

int a,b,c,l,k;

printf("Enter any three positive integers ");

scanf("%d%d%d",&a,&b,&c);

if(a>b)

l = lcm(a,b);

else

l = lcm(b,a);

if(l>c)

k= lcm(l,c);

else

k= lcm(c,l);

printf("LCM of two integers is %d",k);

return 0;

}

int lcm(int a,int b){

int temp = a;

while(1){

if(temp % b == 0 && temp % a == 0)

break;

temp++;

}

return temp;

}

You can use the same logic to write the program to find LCM of more than three numbers. Try writing and if you face any problem. Then let me know.

Similar questions