fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. long long n;
  6. int ans = 0;
  7.  
  8. int main()
  9. {
  10. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  11.  
  12. cin >> n;
  13. n = abs(n);
  14. for (; n; n /= 10)
  15. ans += n % 10;
  16. cout << ans;
  17. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty