Answers for "recursive function to find the sum of the nth term using c"

C
0

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

#include <stdio.h>
int addNumbers(int n);
int main() {
    int num;
    printf("Enter a positive integer: ");
    scanf("%d", &num);
    printf("Sum = %d", addNumbers(num));
    return 0;
}

int addNumbers(int n) {
    if (n != 0)
        return n + addNumbers(n - 1);
    else
        return n;
}
Posted by: Guest on November-13-2020

Code answers related to "recursive function to find the sum of the nth term using c"

Code answers related to "C"

Browse Popular Code Answers by Language