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;
}
#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
Jump to solution
2 Replies
Solution
boualleg sabrina
the answer is 15
Camila_99$$
Camila_99$$9mo ago
Yes 15
Want results from more Discord servers?
Add your server