Question
1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
vector myvector;
7.
int sum (0);
8.
myvector.push_back (100);
9.
myvector.push_back (200);
10.
myvector.push_back (300);
11.
while (!myvector.empty())
12.
{
13.
sum += myvector.back();
14.
myvector.pop_back();
15.
}
16.
cout
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
vector myvector;
7.
int sum (0);
8.
myvector.push_back (100);
9.
myvector.push_back (200);
10.
myvector.push_back (300);
11.
while (!myvector.empty())
12.
{
13.
sum += myvector.back();
14.
myvector.pop_back();
15.
}
16.
cout
Answer: Option B
Was this answer helpful ?
In this program, We are forming a stack and adding the elements and We are finding the total
number of elements that are in stack.
Output:
$ g++ vect1.cpp
$ a.out
600
Was this answer helpful ?
Submit Solution