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