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 Compare Two Strings using strcmp()
  • C Program for Call By Reference
  • C Program to Print ASCII values of Characters
  • C Program for Floyd Triangle
  • C Program to Implement Single Linked List Operations
  • Evaluate Algebraic Expression (ax+b)/(ax-b)
  • C Program to find an Element using Binary Search
  • C Program to Find Nth Fibonacci Number Using Recursion
  • C Program to Design Lexical Analyzer
  • Bubble Sort in C
  • C Program to Print Pascal Traingle
  • C Program to find Size of Integer
  • C Program to Print Reverse of a String without strrev() function
  • C program to find Sum of Digits of a Positive Integer Number
  • C Program to Print Addresses of Variables
  • Privacy Policy
  • Cookie Policy
© programming9.com 2025
Back to top