EmbLogic's Blog

Write a Program to calculate hcf and lcm of three numbers and also input number from user.

#include<stdio.h>
int main()
{

int i,l,a,b,c;
int lcm=1,hcf=1;
int prime[26]={1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};

printf(“enter the numbers”);
scanf(“%d%d%d”,&a,&b,&c);

for(i=1;i<26;i++)
{
l=prime[i];
if(a%l==0 && b%l==0 && c%l==0)
{
hcf*=l;
}
else
{
if(a%l==0)
lcm*=l;

if(b%l==0)
lcm*=l;

if(c%l==0)
lcm*=l;
}

}
}

printf(“\nHcf of three number %d %d %d is %d”,a,b,c,hcf);
lcm=lcm*hcf;
printf(“\nLcm of three number %d %d %d is %d\n”,a,b,c,lcm);
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>