lundi 23 février 2015

Trouble understanding simple recursion in c


My function:



int num(int x)
{
if(x>0)
num(x-1);
else
return 0;
printf("%d",x);
}


This function takes a input x and prints the numbers from 1 upto x.I can't seem to understand how this works, can someone please elaborate. Thanks in advance!





Aucun commentaire:

Enregistrer un commentaire