Here's a sample code I came up for the following question :

Given a tree and a sum, return true if there is a path from the root

down to a leaf, such that adding up all the values along the path

equals the given sum.

Strategy: subtract the node value from the sum when recurring down,

and check to see if the sum is 0 when you run out of tree.

*

Code:int subsums (TREE T, int sum){ if (T==NULL){ return (sum); } else{ int subsum = sum - T->element; return (subsums(T->left, subsum) && subsums(T->right, subsum)); }// else }

if sum!=0 why is the result always printed as 1?

int => it should print any value right? or does is convert to boolean ?