fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin>>n;
  7. int s= 0;
  8. while (n > 0) {
  9. s+=n%10;
  10. n/=10;
  11. }
  12. cout << s<<endl;
  13. return 0;
  14. }
  15.  
Success #stdin #stdout 0.01s 5296KB
stdin
1234
stdout
10