Advertisement
Josif_tepe

Untitled

Dec 2nd, 2023
801
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. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int n;
  7.     cin >> n;
  8.    
  9.     int sum = 0;
  10.     for(int i = n; i > 0; i /= 10) {
  11.         int cifra = i % 10;
  12.         sum += cifra;
  13.     }
  14.     cout << sum << endl;
  15.     return 0;
  16. }
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement