Advertisement
ToniDev

Suma cifrelor unui numar

Sep 22nd, 2023
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int getDigitCountFromNumber(int n) {
  6.     int count = 0;
  7.  
  8.     while (n > 0) {
  9.         count++;
  10.         n /= 10;
  11.     }
  12.  
  13.     return count;
  14. }
  15.  
  16. int main() {
  17.     cout << "Suma cifrelor dintre 1234 si 222 este: " << getDigitCountFromNumber(1234) + getDigitCountFromNumber(222) << endl;
  18.  
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement