Home / Programs / Find Sum of Digits of a Number using Recursion
🚀 Programming Example

Find Sum of Digits of a Number using Recursion

👁 705 Views
💻 Practical Program
📘 Step Learning
Find Sum of Digits of a Number using Recursion

💻 Program Code

#include<stdio.h>
int funSum(int x);
int main(){ 
   int num = 123;
   int f;
   f = funSum(num);
   printf("sum of %d and %d ",num,f);
   return 0; 
}
int funSum(int x){
	int a; 
	int y = 0;
	if(x<=0){
		return 0;
	}
	else{
		a = x%10;
		x = x/10; 
		y = a + funSum(x);
		return y;
   } 
    
}
                        

🖥 Program Output

sum of 123 and 6
                            

📘 Explanation

None
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.