c++

How to Find Sum of Digits of a Number using Recursion in C++ Full Project For Beginners


 

Welcome folks today in this blog post we will be finding sum of digits of a number using recursion in c++ All the full source code of the application is shown below.

 

 

 

 

 

 

In order to get started you need to make a app.cpp file and copy paste the following code

 

 

app.cpp

 

 

#include<iostream>
using namespace std;

int sum=0,rem[10];

int recc(int,int);
int recc(int n,int i)
{
        rem[i]=n%10;
  n=n/10;
  sum+=rem[i];
  if(n>0)
  recc(n,i+1);
  return sum;
}

int main()
{
  int num;
  cout<<"Enter any number: ";
  cin>>num;
  cout<<"Sum of digits: "<<recc(num,0);
  
  return 0;
}

Similar Posts:

    None Found

Leave a Reply

Your email address will not be published. Required fields are marked *