Sum of N Using Recursion

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>

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

int main(int argc, const char * argv[]) {
int num = 5;
printf("%d ", sum(num));
return 0;
}