Answers for "iterative highest common factor hcf"

C++
0

iterative highest common factor hcf

#include <iostream>

using namespace std;
 
int hcf(int a, int b) {
    while (a != b) {
        if (a > b)    
            a = a - b;    
        else   
            b = b - a;    
    }
    return a;
}
 
int main() {
    int a = 24, b = 36;
    cout << hcf(a, b) << endl;
    return 0;
}
Posted by: Guest on June-08-2021

Browse Popular Code Answers by Language