/*HCF AND LCM */
#include<stdio.h>
#include<conio.h>
void hcff(int a,int b,int c)
{
int p,i;
p=(a<b?(a<c?a:c):(b<c?b:c));
for(i=p;i>=1;i--)
{
if(c%i==0 && a%i==0 && b%i==0)
break;
}
printf("the HCF of given number is:%d",i);
}
void lcmf(int a,int b,int c)
{
int p,i;
p=(a>b?(a>c?a:c):(b>c?b:c));
for(i=p;i<=a*b*c;i++)
{
if(i%c==0 && i%a==0 && i%b==0)
break;
}
printf("the LCM of given number is:%d",i);
}
void main()
{
int a,b,c,ch;
clrscr();
printf("enter three number number for HCF And LCM ");
scanf("%d%d%d",&a,&b,&c);
while(1)
{
clrscr();
printf("\n\tEnter 1. for HCF :");
printf("\n\tEnter 2. for LCM :");
printf("\n\tEnter 3. for Exit :");
scanf("%d",&ch);
switch(ch)
{
case 1: hcff(a,b,c);
getch();
break;
case 2: lcmf(a,b,c);
getch();
break;
case 3: return;
default : printf("\n\tWrong choice ");getch();
}
fflush(stdin);
}
getch();
}
0 comments: