Friends, i have written a code for finding HCF but it does not work. please help me in improving this code.Thanks in advance.

#include<iostream>
using namespace std;
int main ()
{
int a,b,c,d,e,f,g,h;
cout<<"Please input two nnumbers:"<<endl;
cin>>a;
cin>>b;
d=a%b;
c=(a-d)/b;
a=b*c+d;
if d==o
cout<<"The hcf is:"<<b<<endl;
if d>>0
{
f=b%d;
e=(b-f)/d;
b=d*e+f;
if f==0
cout<<"The hcf is:"<<d,,endl;
if f>>0
{
h=d%f;
g=(d-h)/f;
d=f*g+h;
if h==0
cout<<"The hcf is:"<<f<<endl;
if h>>0
cout<<"The Hcf could not be found out due to the some problems";
}
}
return 0;
}

1) Welcome to Daniweb. One of the first things you need to know about this board is that when you post code the boad will gobble up your indenting and other formatting and make your code very difficult to read unless you enclose it in code tags. The use of code tags involves placing [ code ] before your code and [ /code ] after your code, though take the spaces between the words code and /code out when using the tags.

2) Learn to be as specific as possible when requesting help. For example your question is about as specific as me saying "I don't feel good". Does the code not compile? compile but with errors? not run? run but gives you wrong output?

3) Avoid use of abbreviations. HCF and gcd are probably synonyms, but it would be better if you wrote out Highest Common Factor at least once to prove it is the same idea as greatest common denominator.

4) Look into loops instead of essentially writing the same code three times.

5) Your algorithm is reminiscent of Euclids algorithm which can be Googled to compare with your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.