Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Add digits of a number - Using recursion Function in C

#include <stdio.h>
 
int add_dig_no(int);
 
int main() {
  int no,output;
 
  scanf("%d", &no);
 
  output= add_dig_no(no);
 
  printf("%d\n",output);
 
  return 0;
}
 
int add_dig_no(int n) {
  static int sum = 0;
 
  if (n == 0) {
    return 0;
  }
 
  sum = n%10 + add_digits(n/10);
 
  return sum;
}