**eg. H.C.F of 11,22,33 is 11**

**L.C.M of 11,22,33 is 66**

**-------------------------------------**

**H.C.F of 2,3,4 is 1**

**L.C.M of 2,3,4 is 24**

**#include**

**<iostream.h>**

**#include**

**<conio.h>**

**void main()**

**{**

**int a, b, c; // three numbers**

**int hcf,lcm;**

**//calculate the minimum of three numbers**

**int min = (a < b ? a : b);**

**min = (min < c ? min : c);**

**for( int i = min; i>0; i--)**

**{**

**if(a%i == 0 && b%i == 0 && c%i == 0)**

**{**

**hcf = i;**

**break;**

**}**

**}**

**lcm = (a*b*c)/hcf;**

**cout<<" \n The H.C.F of " << a <<" , " << b << " , " << c << "is " << hcf;**

**cout<<" \n The L.C.M of " << a <<" , " << b << " , " << c << "is " << lcm;**

**getch();**

**}**

**/* Similarly you can calculate HCF of 2 numbers or 4 numbers and so on. */**

u shud hav to input 3 nos, otherwise the programming runs wrong.....

ReplyDeleteC++ Program to Find HCF of two numbers

ReplyDeleteTo find the HCF or GCD of two or more numbers, make prime factors of the numbers and choose the common prime factors. Then the take the highest common factor this highest common factor is HCF of number.