1: #include<iostream.h>
2: #include<conio.h>
3: class HCF
4: {
5: int a,b;
6: public:
7: void gcd();
8: void input(){
9: cout<<"Enter two numbers :"<<endl;
10: cin>>a>>b;
11: }
12: };
13: void HCF::gcd()
14: {
15: int m,n;
16: m=a;
17: n=b;
18: while(m!=n)
19: {
20: if(m>n)
21: m=m-n;
22: else
23: n=n-m;
24: }
25: cout<<"\nH.C.F of"<<a<<" & "<<b<<" is "<<m;
26: }
27: int main()
28: {
29: HCF hcf;
30: hcf.input();
31: hcf.gcd();
32: getch();
33: return 0;
34: }
This blog aims at helping you learn C,C++ and Java programming languages and thus enabling you to use its immense possibilities in the computing world.
Program to find HCF of two Numbers in C++ Using Class
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
leave a comment here