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

Written by: RajaSekhar
  • 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 Implement Structure with Pointers
  • C Program for Circumference of a Circle
  • C Program to Simulate PRIORITY CPU Scheduling Algorithm
  • C program to find Sum of Digits of a Positive Integer Number
  • Bubble Sort in C
  • C Program for Swapping of Two Numbers Without Using Third Variable
  • C Program for Optimal Page Replacement Algorithm
  • C Program to Find Prime Factors of a Given Positive Number
  • C Program to Print Elements of Array Using Pointers
  • C Program for Monthly Bill of a Newspaper
  • C Program to Find Area of a Triangle
  • C Program to Find Area of Rectangle
  • C Program to Find Length of a String Using STRLEN()
  • Implementation of Stack Using Array in C
  • C Program to Solve Sum of Series 1-x2/2! +x4/4!-x6/6!+x8/8!-x10/10!
  • Privacy Policy
  • Cookie Policy
© programming9.com 2025
Back to top