c++ - Conversion of a recursive function -


the following program recursive function computes value 2 positive integers.

int riddle (int i, int j) {    if (j==0) return i;     return riddle(j, i%j); } 

i wondering how 1 while-loop can convert program non-recursive function without if -statement?

thank help

assuming i>j, prog find hcf of 2 no.s using recursion can done using while. try :

int i=val1,j=val2;             while (j != 0)             {                 int t;                 t = j;                 j = % j;                 = t;             } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

qt - How to embed QML toolbar and menubar into QMainWindow -