Top MNC interview question which will be very useful for beginners to crack the interview and for there future careers

test

Breaking

Post Top Ad

Your Ad Spot

Monday, December 28, 2020

Find the Sum of digits using C++

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---------

Post Top Ad

Your Ad Spot