Josif_tepe

Untitled

Jan 24th, 2026
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.27 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int n;
  6.     cin >> n;
  7.    
  8.     int sum = 0;
  9.     while(n > 0) {
  10.         int cifra = n % 10;
  11.         n /= 10;
  12.        
  13.         sum += cifra;
  14.     }
  15.    
  16.     cout << sum << endl;
  17.    
  18.     return 0;
  19. }
  20.  
  21.  
  22.  
  23.  
  24.  
Advertisement
Add Comment
Please, Sign In to add comment