- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find HCF (Highest Common Factor) of 2 Numbers in C++

In this tutorial, we will be discussing a program to find HCF (highest common factor) of two numbers.

For this we will be provided with two numbers. Our task is to find the highest common factor (HCF) of those numbers and return it.

## Example

#include <stdio.h> //recursive call to find HCF int gcd(int a, int b){ if (a == 0 || b == 0) return 0; if (a == b) return a; if (a > b) return gcd(a-b, b); return gcd(a, b-a); } int main(){ int a = 98, b = 56; printf("GCD of %d and %d is %d ", a, b, gcd(a, b)); return 0; }

## Output

GCD of 98 and 56 is 14

- Related Questions & Answers
- C program to find Highest Common Factor (HCF) and Least Common Multiple (LCM)
- Program to find highest common factor of a list of elements in Python
- Finding two numbers given their sum and Highest Common Factor using JavaScript
- Program to find GCD or HCF of two numbers in C++
- Java program to find the GCD or HCF of two numbers
- Print the kth common factor of two numbers
- Program to find HCF iteratively in C++
- Program to find GCD or HCF of two numbers using Middle School Procedure in C++
- Program to find the common ratio of three numbers in C++
- 8085 Program to find the HCF of two given bytes
- Golang Program to round up the next highest power of 2.
- Program to find the HCF of two given bytes in 8085 Microprocessor
- Find HCF of two numbers without using recursion or Euclidean algorithm in C++
- C++ Program for Common Divisors of Two Numbers?
- Python Program for Common Divisors of Two Numbers

Advertisements