- 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

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.

#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; }

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 GCD or HCF of two numbers in C++
- Finding two numbers given their sum and Highest Common Factor using JavaScript
- Program to find HCF iteratively in C++
- Print the kth common factor of two numbers
- Java program to find the GCD or HCF of two numbers
- Program to find the common ratio of three numbers in C++
- Program to find GCD or HCF of two numbers using Middle School Procedure in C++
- Find HCF of two numbers without using recursion or Euclidean algorithm in C++
- C++ Program for Common Divisors of Two Numbers?
- 8085 Program to find the HCF of two given bytes
- Golang Program to round up the next highest power of 2.
- C++ Program for the Common Divisors of Two Numbers?
- Largest Component Size by Common Factor in C++
- Program to find length of longest common subsequence in C++

Advertisements