Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Program to find HCF iteratively in C++
In this tutorial, we will be discussing a program to find HCF iteratively.
For this, we will be provided with two numbers. Our task is to calculate the HCF of the given numbers using an iterative function.
Example
#include <bits/stdc++.h>
using namespace std;
int get_HCF(int a, int b){
while (a != b){
if (a > b)
a = a - b;
else
b = b - a;
}
return a;
}
int main(){
int a = 60, b = 96;
cout << get_HCF(a, b) << endl;
return 0;
}
Output
12
Advertisements
