35657

Untitled

Nov 2nd, 2023
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.25 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int main() {
  7.  
  8.     setlocale(LC_ALL, "ru");
  9.  
  10.     int x;
  11.  
  12.     int sum = 0;
  13.  
  14.     cout << "Введите число: ";
  15.     cin >> x;
  16.  
  17.     for (; x > 0; x /= 10) {
  18.         sum += x % 10;
  19.     }
  20.  
  21.     cout << sum << endl;
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment