Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to calculate the HCF (Highest Common Factor) of two integers using recursion in C

1 Answer

0 votes
#include <stdio.h> 

int getHCF_Recursion(int a, int b) {
    while (a != b) {
        if (a > b) {
            return getHCF_Recursion(a - b, b);
        }
        else {
            return getHCF_Recursion(a, b - a);
        }
    }
    return a;
}
  
int main(void)
{   
    int a = 12, b = 15;
      
    printf("The HCF (Highest Common Factor) of %d and %d is: %d\n", a, b, getHCF_Recursion(a, b));
 
    return 0;
}
  
  

   
/*
run:
 
The HCF (Highest Common Factor) of 12 and 15 is: 3
  
*/

 



answered Jan 17, 2021 by avibootz
edited Jan 17, 2021 by avibootz
...