LordMirai

stiva

Apr 13th, 2021 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. int sumCf(int n) {
  2.     int s = 0;
  3.     while (n) {
  4.         s += n % 10;
  5.         n /= 10;
  6.     }
  7.     return s;
  8. }
  9.  
  10. void probStiva() {
  11.     stack <int> stiva;
  12.     int n;
  13.     cout << "Cate numere sa se genereze?\nn = "; cin >> n;
  14.     for (int i = 0; i < n; i++) {
  15.         stiva.push(rand() % 1000);
  16.     }
  17.    
  18.     cout << "Stiva originala:\n";
  19.     stack <int> stiva2 = stiva;
  20.     for (int i = 0; i < n; i++) {
  21.         cout << stiva2.top() << "  ";
  22.         stiva2.pop();
  23.     }
  24.     cout << endl << "Stiva procesata:\n";
  25.  
  26.     for (int i = 0; i < n; i++) {
  27.         int s = sumCf(stiva.top());
  28.         if (s >= 10) {
  29.             cout << stiva.top() << " (" << s << ")  ";
  30.         }
  31.         stiva.pop();
  32.     }
  33. }
  34.  
Add Comment
Please, Sign In to add comment