Coding Challenges < C >

What will be the output of this program when num is 5?
#include <stdio.h>

int computeSum(int n) {
    if (n == 0)
        return 0;
    else
        return n + computeSum(n - 1);
}

int main() {
    int num = 5;
    int result = computeSum(num);
    printf("Result: %d\n", result);
    return 0;
}
Solution
the answer is 15
Was this page helpful?