Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int sumCf(int n) {
- int s = 0;
- while (n) {
- s += n % 10;
- n /= 10;
- }
- return s;
- }
- void probStiva() {
- stack <int> stiva;
- int n;
- cout << "Cate numere sa se genereze?\nn = "; cin >> n;
- for (int i = 0; i < n; i++) {
- stiva.push(rand() % 1000);
- }
- cout << "Stiva originala:\n";
- stack <int> stiva2 = stiva;
- for (int i = 0; i < n; i++) {
- cout << stiva2.top() << " ";
- stiva2.pop();
- }
- cout << endl << "Stiva procesata:\n";
- for (int i = 0; i < n; i++) {
- int s = sumCf(stiva.top());
- if (s >= 10) {
- cout << stiva.top() << " (" << s << ") ";
- }
- stiva.pop();
- }
- }
Add Comment
Please, Sign In to add comment