Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the output of the following code? (a) int *secret; int j; secret = new i

ID: 3680849 • Letter: W

Question

What is the output of the following code?

(a)

int *secret;

int j; secret = new int[10];

secret[0] = 10;

for (j = 1; j < 10; j++)

secret[j] = secret[j - 1] + 5;

for (j = 0; j < 10; j++) cout << secret[j] << " "; cout << endl;

(b)

int *p;                           

int *q;                           

p = new int[5];

p[0] = 5;

for (int i = 1; i < 5; i++)

   p[i] = p[i - 1] + 2 * i;

cout << "Array p: ";

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

   cout << p[i] << " ";

cout << endl;

q = new int[5];

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

   q[i] = p[4 - i];

cout << "Array q: ";

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

   cout << q[i] << " ";

cout << endl;

(c)

p = new int* [5];

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

   p[i] = new int[3];

for (int i = 1; i < 5; i++)

   for (int j = 0; j < 3; j++)

        p[i][j] = 2 * i + j;

for (int i = 1; i < 5; i++)

{

   for (int j = 0; j < 3; j++)

        cout << p[i][j] << " ";

   cout << endl;

}

Explanation / Answer

a)10 15 20 25 30 35 40 45 50 55

b)Array p: 5 7 11 17 25

Array q: 25 17 11 7 5

c)2 3 4

4 5 6
6 7 8
8 9 10

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote