Advertisement
JakubJaneczek

Zadanie 24*

Apr 8th, 2020
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. int a,b;
  5.  
  6. int suma_cyfr(int a)
  7. {
  8.     while(a%10==0)
  9.     {
  10.         a=a/10;
  11.     }
  12.     int b=1;
  13.     int c=1;
  14.     while (b<=a)
  15.     {
  16.         b=b*10;
  17.     }
  18.     while(a>1)
  19.     {
  20.         while(a>b)
  21.         {
  22.             a=a-b;
  23.             c++;
  24.         }
  25.         b=b/10;
  26.     }
  27.     return c;
  28. }
  29.  
  30. int main()
  31. {
  32.     b=10;
  33.     while(b>=10)
  34.     {
  35.         cout << "Podaj liczbe" << endl;
  36.         cin >> a;
  37.         b=suma_cyfr(a);
  38.         cout << suma_cyfr(a)<< endl;
  39.  
  40.     }
  41.         cout << "Suma cyfr z 25" << endl;
  42.         cout << suma_cyfr(25) << endl;
  43.         cout << "Suma cyfr z 252" << endl;
  44.         cout << suma_cyfr(252) << endl;
  45.         cout << "Suma cyfr z 2525" << endl;
  46.         cout << suma_cyfr(2525) << endl;
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement