fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t;
  6. cin >> t;
  7. while(t--){
  8. int n;
  9. cin >> n;
  10. int temp, r, sum = 0;
  11. temp = n;
  12. while(temp != 0){
  13. r = temp % 10;
  14. sum = sum + r;
  15. temp = temp / 10;
  16. }
  17. cout << sum << endl;
  18. }
  19. return 0;
  20. }
Success #stdin #stdout 0.01s 5280KB
stdin
3 
12345
31203
2123
stdout
15
9
8