Question:
Find the Sum of digits using python?
Explanation:
We need to find the sum given digits.
For Example:
digits=123
Result:6
Program:
#include<iostream>
using namespace std;
class Digit
{
public: int sumDigits(int n)
{
return n == 0 ? 0 : n%10 + sumDigits(n/10) ;
}
};
int main(void)
{
Digit g;
cout<<g.sumDigits(687);
return 0;
}
---------End---------