iterative highest common factor hcf

Solutions on MaxInterview for iterative highest common factor hcf by the best coders in the world

showing results for - "iterative highest common factor hcf"
Dior
02 Mar 2020
1#include <iostream>
2
3using namespace std;
4 
5int hcf(int a, int b) {
6    while (a != b) {
7        if (a > b)    
8            a = a - b;    
9        else   
10            b = b - a;    
11    }
12    return a;
13}
14 
15int main() {
16    int a = 24, b = 36;
17    cout << hcf(a, b) << endl;
18    return 0;
19}
similar questions
queries leading to this page
iterative highest common factor hcf