USING RECURSION TO GET SUM e.g 12345=1+2+3+4+5=15.

#include <iostream>
using namespace std;
int num;
int number(int num);

int main(){


for(int x=0;x<=10;x++){
cout<<"enter a five digit number "<<endl;
cin>>num;
cout<<x<<"  = ";
int as=number(num);
cout<<as<<endl;

}

}
int number(int num){
if(num==0){
return 0;
}
else{
return (num%10)+number(num/10);
}
}
Previous
Next Post »

Comments:

Disqus Shortname