u

Sunday 3 June 2012

C++ Program to compute the lcm and hcf using class

C++ Program to compute the lcm and hcf using class



#include<iostream.h>
#include<conio.h>
class work
     { private:
           int a,b;
       public:
           work()
           { a = 0;
             b = 0;
           }
           ~work()
           {}
           compute()
           {
             cout<<"Enter any two numbers";
             cin>>a>>b;
      int p,hcf,i,lcm;
      p=a*b;
      for(i=1;i<=p;i++)
      { if(a%i==0 && b%i==0)
        hcf =i;
        }
        lcm=p/hcf;
        cout<<"The lcm is "<<lcm;
        cout<<endl;
        cout<<"The hcf is "<<hcf;
          }

     };

      main()
      { clrscr();
      work amit;
      amit.compute();
        getch();
        return 0;
      }
 

1 comments:

C++ Program to Find HCF of two numbers

To 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.

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More