0

I am new in this programming field,so i am facing a lots of problem while writing code.My question is to find hcf and lcm of 3 integers given by the user....I got stucked at half, so please help me to complete this code, I know how to calculate hcf but i don't get any idea to calculate lcm in same program.

#include<stdio.h>
#include<conio.h>

void main()
{
    int i,min,a,b,c,hcf,lcm;
    printf("Enter three numbers :");
    scanf("%d%d%d", &a,&b,&c);
    
    min = a;
    if(b<min)
    {
        min = b;
    }
    if(c<min)
    {
        min = c;
    }
    for(i=min ; i>=1; i--)
    {
        if(a%i==0 && b%i==0 && c%i==0)
        {
            hcf = i;
            break;
        }
    }
    printf("HCF is %d",hcf);
    lcm = 
    printf("\nLCM is %d",lcm);
    getch();
}
Eva Maria
  • 1
  • 1

1 Answers1

0

It seems you choosed to brute-force the HCF. You can do the same for LCM.

for(i=1 ; ; i++)
{
    if(i%a==0 && i%b==0 && i%c==0)
    {
        lcm = i;
        break;
    }
}
MikeCAT
  • 73,922
  • 11
  • 45
  • 70