programming9
  • Flowcharts
  • Programs
      • Back
      • C Programs
      • C++ Programs
      • Java Programs
      • Python Codes
      • HTML Codes
      • Java Script Codes
      • SQL Codes
  • Tutorials
      • Back
      • Java Tutorials
      • Competitive Programming
      • Python Tutorials
      • C Programming
  • Blog
  • Login

C Program for Sum of Digits of a Number using Recursion

Details
Written by: RajaSekhar
Category: C Programs
  • basic c programs
  • Sum of digits of a number
#include<stdio.h>

int doSum(int);
int main()
{
    int num,sum;
    printf("Enter a Number to perform Sum : ");
    scanf("%d",&num);

    sum = doSum(num);

    printf("Sum of Digits of Given Number is:  %d",sum);
    return 0;
}

int doSum(int num)
{

    static int sum =0,r;

    if(num!=0)
    {
        r=num%10;
        sum=sum+r;
        doSum(num/10);
    }

    return sum;
}

 OUTPUT:

Enter a Number to perform Sum : 258
Sum of Digits of Given Number is:  15
Previous article: C Program to find Area of a Circle Prev Next article: C Program for Sum of Digits of a Number Next
  • C Program to Check Given Number is PRIME or Not
  • Implementation of Stack Using Array in C
  • GCD of Two Numbers Without using LCM in C
  • C Program to convert Celsius to Fahrenheit
  • Bubble Sort in C
  • C Program to find Area of a Circle
  • C Program to Print Pascal Traingle
  • C Program to Print PRIME Numbers in a Given Range
  • C Program to Find Length of a String Using STRLEN()
  • Swap Two Static Numbers Using C
  • C Program to Copy a String with out using strcpy() Built in Function
  • C Program to Find Roots of a Quadratic Equation
  • C Program to Implement BINARY SEARCH
  • C Program to Implement STACK Operations Using Pointers
  • C Program to Implement Single Linked List Operations
  • Privacy Policy
  • Cookie Policy
© programming9.com 2026
Back to top