Advertisement
Josif_tepe

Untitled

Nov 24th, 2023
567
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.     int n;
  9.     cin >> n;
  10.     int sum = 0;
  11.    
  12.     for(int i = n; i > 0; i /= 10) {
  13.         int cifra = i % 10;
  14.         sum += cifra;
  15.     }
  16.     cout << sum << endl;
  17.  
  18.     return 0;
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement