sum of stack elements in c code example
Example: sum of stack c++
stack<int> si;
int sum = 0;
stack<int> tsi(si);
while (!tsi.empty()) {
sum += tsi.top();
tsi.pop();
}
stack<int> si;
int sum = 0;
stack<int> tsi(si);
while (!tsi.empty()) {
sum += tsi.top();
tsi.pop();
}