I've already written this function but the only output i get for any input is '0'. I know that its the same 0 from sum=0; because when i change 'sum' to any other number at the beginning, that number is outputted. its almost as if the 'if' clause is being skipped completely.
Here is the code:
Expand|Select|Wrap|Line Numbers
- int reverse(int num)
- {
- int sum,z;
- sum=0;
- if(num>0)
- {
- z=num%10;
- sum=(sum*10)+z;
- reverse(num/10);
- }
- else
- return (sum);
- }