Answer to Question #242040 in C++ for jonny

Question #242040

what will be the output of the following code? Rough work must be done as well.

int[] values={1,3,5,7,9,11,13,15,17,19};

    Stack s=new Stack();

    for(int i=0;i<values.length;i++)

    {

        s.push(values[i]);

    }

    int n=25;

    for(int i=0;i<4;i++)

    {

        n+=s.pop();

    }

    for(int i=0;i<2;i++)

    {

        n-=s.pop();

    }

    cout<<"\n"<<endl;


1
Expert's answer
2021-09-25T05:20:37-0400
The stack operates in LIFO(Last In First Out) manner.
Therefore, the four element to be removed from the stack will be 19, 17, 15, and1 3.
 These elements will be added to to 25, i.e 25 + 19 + 17 + 15 + 13 = 89

89 - (11 + 9)  = 69
Answer is = 69

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS