recursive function to find the sum of the nth term using c

Solutions on MaxInterview for recursive function to find the sum of the nth term using c by the best coders in the world

showing results for - "recursive function to find the sum of the nth term using c"
Giacomo
13 Aug 2018
1#include <stdio.h>
2int addNumbers(int n);
3int main() {
4    int num;
5    printf("Enter a positive integer: ");
6    scanf("%d", &num);
7    printf("Sum = %d", addNumbers(num));
8    return 0;
9}
10
11int addNumbers(int n) {
12    if (n != 0)
13        return n + addNumbers(n - 1);
14    else
15        return n;
16}
17