Trending This Week:

test

Post Top Ad

Your Ad Spot

Monday, June 13, 2022

C++ program to find HCF.

 







The Highest Common Factor
The full form of HCF in Maths is the Highest Common Factor. HCF of two or more numbers is the greatest factor that divides the numbers. For example, 2 is the HCF of 4 and 6.


C++ program to find HCF.


#include <iostream>
using namespace std;
int main() {
  int a, b, hcf, r;
  cout << "Enter two numbers : ";
  cin >>a>>b;
  while (true) {
    hcf = b;
    r = a % b;
    a = b;
    b = r;
    if (b == 0) {
      break;
    }
  }
  cout << "HCF is " << hcf;
}

Output :








No comments:

Post a Comment

Post Top Ad

Your Ad Spot