Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //you could do this with only math and no strings, but why should you when this is simpler?
- #include <iostream>
- #include <string>
- int main() {
- std::string N;
- std::cin >> N;
- int brCif = N.length();
- int suma = 0;
- for (int i = 0; i < brCif; i++) {
- char x = N.at(i);
- int ix = x - '0'; //char --> int
- suma += ix;
- }
- std::cout << suma << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment