Advertisement
Lukasz_Miskiewicz

Zadanie 24

Mar 31st, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int a,b;
  4.  
  5. int suma_cyfr(int a)
  6. { int b=1;
  7. int c=1;
  8. while(a%10==0)
  9. {a=a/10;}
  10. while (b<=a)
  11. {b=b*10;}
  12. while(a>1)
  13. {while(a>b)
  14. {
  15. a=a-b;
  16. c++;
  17. }
  18. b=b/10;
  19. }
  20. return c;
  21. }
  22.  
  23. int main()
  24. {
  25. b=10;
  26. while(b>=10)//liczba mniejsza od 10 kończy program
  27. {
  28. cout<<"podaj liczbe naturalna lub wynik poprzedniej sumy"<<endl;
  29. cin>>a;
  30. b=suma_cyfr(a);
  31. cout<<"suma cyfr wynosi "<< suma_cyfr(a)<<endl;
  32. }
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement