Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Sum of integers in the given number using recursive method in C++

//SUM OF DIGITS IN THE GIVEN NUMBER(USING RECURSIVE METHOD)

#include<iostream.h>
#include<conio.h>
class adddigit

{
public:
int add_digit(int no)
{
int sum=0;
if(no == 0){
return 0;
}
sum = no%10 + add_digit(no/10);
return sum;
}
};

void main()
{
adddigit a;
int n,output;
clrscr();
cout<<" Enter the number:";
cin>>n;
output= a.add_digit(n);
cout<<"Sum of digits in the given number:"<< output;
getch();
}