find gcd iteratively
snippet in c

find gcd iteratively

user279

// C program to find HCF of two 
// numbers iteratively. 
#include <stdio.h> 
  
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 = 60, b = 96; 
    printf("%d\n", hcf(a, b));  
    return 0; 
}