JakubKaczmarek_123

zadanie 13

Jan 29th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <string>
  4. using namespace std;
  5. int SUMA_CYFR(int a);
  6. int main(){
  7. cout << SUMA_CYFR(123456789) << endl;
  8. cout << SUMA_CYFR(2159) << endl;
  9. cout << SUMA_CYFR(1221789) << endl;
  10. cout << SUMA_CYFR(12656789) << endl;
  11. cout << SUMA_CYFR(189) << endl;
  12.  
  13. }
  14.  
  15.  
  16. int SUMA_CYFR(int a){
  17. string b = to_string(a);
  18. int c = 0;
  19. for (int i = 0; i < b.length(); i++) c += b[i] - '0';
  20. return c;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment