sum of two numbers using recursion code example

Example 1: c program to find the sum of given number using recursion

# include <stdio.h>
int sum(int number);
int main
{
 int n;
 int a;
 printf("enter a number");
 scanf("%d,&n);
 a=sum(n);
 printf("sum=%d",a);
 }
int sum(int number)
{
  if (number==0)
    return 0;
  return(number%10+sum(number/10);
 }

Example 2: 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;
}