JakubKaczmarek_123

zadanie 13

Jan 29th, 2021
68
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 << "wprowadz liczbe: " << endl;
  8. int a;
  9. cin >> a;
  10. int wynik = SUMA_CYFR(a);
  11. while (wynik >= 10) wynik = SUMA_CYFR(wynik);
  12. cout << "wynik to: " << wynik << endl;
  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. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment