recursive function to normal function

Hello there. i'm trying to find gcd between 2 numbers but i did with recursive function. can anyone help do it with normal function ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  int gcd(int num1, int num2)
{
 if (num1==0)   
    return num2; 
 if (num2==0) 
    return num1; 
   
    if (num1==num2)                                                
    return num1;
                  
    if (num1 > num2)           
    return gcd(num1-num2, num2);  
    else
    return gcd(num1, num2-num1); 
}
Did you try searching the internet? There is code out there for finding the GCD using if statements and either a for or while loop.

https://duckduckgo.com/?q=c%2B%2B+gcd+code&t=ffsb&ia=web

First link is a "winner:"
https://www.programiz.com/cpp-programming/examples/hcf-gcd

A while loop variant:
http://www.trytoprogram.com/cpp-examples/cplusplus-program-to-find-gcd-hcf/
Topic archived. No new replies allowed.