I need help for my test

So... you've just dumped a load of homework questions on us, and are hoping someone will do it for you?

No. If you've been given those questions, it's because your teacher believes you have been taught the things you need to be able to answer them.

If there are specific things you don't understand, then by all means, ask about those specific issues, and we'll help you understand them. But don't expect us to just do your homework for you.
Technically, yes, I am here for answers. But, I'm also here to better understand how to solve these programs.

And no. This is not homework. Our teacher gave us programs that WILL be similar to the following test . There were lots more problems but these are the ones I don't understand. If you don't want to help, I can respect that.

I am just here to understand these problems and learn how to solve them.

P.S Our teacher is stubborn and close to retirement so she doesn't give us detailed information and I am trying my best to learn these problems.
First compile and run the program to see what the result is.
For example, for the first program, when the input is 3: http://coliru.stacked-crooked.com/a/0747cf304e3a1456

The try to understand why the result is what it is. If you can't explain to yourself why the result came out that way, annotate the program with a few diagnostic messages and run it again.
For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// What will the answer be if x becomes 3?
#include <iostream>
using namespace std;

int main()
{
    int  p,x,i;
    cin>>x;
    cout << "x == " << x << '\n' ;
    p=1;
    
    for (i=1; i<=4; i++)
    {
        cout << "i == " << i << "  p == " << p ;
        p=p*x;
        cout << "  after p=p*x, p == " << p << '\n' ;
    }
        
    cout<<p<<endl;
    return 0;
}

x == 3
i == 1  p == 1  after p=p*x, p == 3
i == 2  p == 3  after p=p*x, p == 9
i == 3  p == 9  after p=p*x, p == 27
i == 4  p == 27  after p=p*x, p == 81
81

http://coliru.stacked-crooked.com/a/d94973b5b855976b
I understand. Thank you. It was very simple.
Topic archived. No new replies allowed.