- #1
Raghav Gupta
- 1,011
- 76
Homework Statement
I have to find GCD or HCF of two numbers.
Homework Equations
The Attempt at a Solution
Code:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,m,n,temp;
cout<<"Enter two numbers\n";
cin>>m>>n;
do
{
if(n>m)
{
temp=n;
n=m;
m=temp; // this loop I think it is correct but still it is going to an infinite loop.
}
i=n;
if(m%i==0&&n%i==0)
break;
i--;
}while(i>=1);
cout<<"The HCF is\t"<<i;
getch();
}