fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. int t;
  7. cin >> t;
  8. while(t--){
  9. int n,sum = 0;
  10. cin >> n;
  11. while(n>0){
  12. sum += n % 10;
  13. n /= 10;
  14. }
  15. cout << sum << endl;
  16. }
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 5284KB
stdin
8
77
21
40
34
19
84
10
99
stdout
14
3
4
7
10
12
1
18