C# Program to Find Sum of Digits of a Number Using Recursion Last Updated : 22 Apr, 2022 Comments Improve Suggest changes Like Article Like Report Given a number, we need to find the sum of digits in the number using recursion. In C#, recursion is a process in which a function calls itself directly or indirectly and the corresponding function is known as a recursive function. It is used to solve problems easily like in this article using recursion we will find the sum of digits of a number. Example Input: 456 Output: 15 Input: 123 Output: 6 Approach: To find the sum of digits of a number using recursion follow the following approach: We call the SumOfDigits function with the argument n.In function, the last digit is retrieved by n % 10.The function is recursively called with argument as n / 10.[i.e. n % 10 + SumOfDigit(n / 10)]The function is called recursively until the n > 0. Example 1: C# // C# program to find the sum of digits of a number // using recursion using System; class GFG{ // Method to check sum of digit using recursion static int SumOfDigit(int n) { // If the n value is zero then we // return sum as 0. if (n == 0) return 0; // Last digit + recursively calling n/10 return(n % 10 + SumOfDigit(n / 10)); } // Driver code public static void Main() { int n = 123; int ans = SumOfDigit(n); Console.Write("Sum = " + ans); } } OutputSum = 6 Example 2: C# // C# program to find the sum of digits of a number // using recursion // Here, we take input from user using System; class GFG{ // Method to check sum of digit using recursion static int SumOfDigit(int n) { // If the n value is zero then we return sum as 0. if (n == 0) return 0; // Last digit + recursively calling n/10 return (n % 10 + SumOfDigit(n / 10)); } // Driver code public static void Main() { int number, res; // Taking input from user Console.WriteLine("Hi! Enter the Number: "); number = int.Parse(Console.ReadLine()); res = SumOfDigit(number); // Displaying the output Console.WriteLine("Sum of Digits is {0}", res); Console.ReadLine(); } } Output: Hi! Enter the Number: 12345 The Sum of Digits is 15 Comment More infoAdvertise with us Next Article C# Program to Find Sum of Digits of a Number Using Recursion R raghu135ram Follow Improve Article Tags : C# CSharp-programs Similar Reads How to find Sum the Digits of a given Number in PHP ? We will explore how to find the sum of the digits of a given number in PHP. This task involves extracting each digit from the number and adding them together to get the final sum. Table of Content Using a loop to extract digits one by oneUsing mathematical operations to extract digitsUsing a loop to 2 min read JavaScript Program for Sum of Digits of a Number using Recursion We are given a number as input and we have to find the sum of all the digits contained by it. We will split the digits of the number and add them together using recursion in JavaScript. Table of Content Recursively Summing DigitsUsing string manipulation with recursionRecursively Summing DigitsIn th 2 min read C Program to Find Sum of Natural Numbers using Recursion Natural numbers include all positive integers from 1 to infinity. There are multiple methods to find the sum of natural numbers and here, we will see how to find the sum of natural numbers using recursion. Example Input : 5Output : 15Explanation : 1 + 2 + 3 + 4 + 5 = 15 Input : 10Output : 55Explanat 2 min read Java Program to Reverse a Number and find the Sum of its Digits Using do-while Loop Problem Statement: The number is supposed to be entered by the user be it any random number lying within the primitive data-type holding the number. First, the number needs to be reversed. Secondary the sum of the number is to be calculated with the constraint to use a do-while loop. do-while loop: 6 min read Python Program to Find Sum of First and Last Digit Given a positive integer N(at least contain two digits). The task is to write a Python program to add the first and last digits of the given number N. Examples: Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two (1 + 7) is equal to 8.Input: N = 73 5 min read C Program to Calculate Sum of Natural Numbers Here we will build a C program to calculate the sum of natural numbers using 4 different approaches i.e. Using while loopUsing for loopUsing recursionUsing Functions We will keep the same input in all the mentioned approaches and get an output accordingly. Input: n = 10 Output: 55 Explanation: The s 3 min read C Program to Add 2 Binary Strings Given two Binary Strings, we have to return their sum in binary form.Approach: We will start from the last of both strings and add it according to binary addition, if we get any carry we will add it to the next digit.Input: 11 + 11Output: 110C// C Program to Add 2 Binary Strings // and Print their B 8 min read Palindrome Number Program in C Palindrome numbers are those numbers that remain the same even after reversing the order of their digits. In this article, we will learn how to check whether the given number is a palindrome number using C program.ExamplesInput: 121Output: YesExplanation: The number 121 remains the same when its dig 3 min read How to Handle Large Numbers in C? In C, the maximum value that an integer type variable can store is limited. For instance, the maximum value that an long long int can hold in 64-bit compiler is 9223372036854775807. So, how can we handle numbers that are larger than this? In this article, we will learn how to handle large numbers in 2 min read Sum of digit of a number using recursion Given a number, we need to find sum of its digits using recursion.Examples: Input: 12345Output: 15Explanation: Sum of digits â 1 + 2 + 3 + 4 + 5 = 15Input: 45632Output: 20 Approach:To understand the algorithm, consider the number 12345 and refer to the illustration below..Extract the last digit: 123 3 min read Like