Write a program that defines a recursive function sum_ints(x) that returns the sum of all the ints in x. Here is how to "sum all the ints in x": * If x is an int, return x. * If x is a list, return the sum of all the ints in x, or in lists contained in x. * Otherwise, return 0. Here are some examples: * sum_ints(3) = 3 * sum_ints('a') = 0 * sum_ints('3') = 0 * sum_ints(3.0) = 0 * sum_ints([3]) = 3 * sum_ints([]) = 0 * sum_ints([[[[3]]]]) = 3 * sum_ints([[2], 3, [[4, 5, 'a']]]) = 14 * sum_ints({1: 2, 3: 4}) = 0 * sum_ints((1, 2, 3, 4)) =
This is not do your assignment forum,you can try yourself and if your struck we can help you
hmmm, here is a hint int main() { \\find sum of 3 int val = sum_all_ints(3); } int sum_all_ints(int i) { \\Check values and strip rubbish \\check boundary condition. very important and return 0, what about negatives? return (i + sum_all_ints( i-1 )); } Haven't test or even compiled it but you should get the idea
well Im more of python person
A Pythonic guy will not ask this question for others to answer.
Well, take it for what it is and run with it :D
Join our real-time social learning platform and learn together with your friends!