← Quiz: C Functions and Recursion: all 10 questions
Quiz: C Functions and Recursion · Question 2 of 10
What does this print? (code)
What does this print?
#include <stdio.h>
int f(int n) {
if (n == 0) return 0;
return n + f(n - 1);
}
int main(void) {
printf("%d", f(5));
return 0;
}
- A.5
- B.15
- C.120
- D.10
Answer & explanation
Correct answer: 15
f(5) = 5 + 4 + 3 + 2 + 1 + 0 = 15.
Can you get the rest right without peeking?
Take the timed Quiz: C Functions and Recursion quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →