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

57) In C++: Suppose that list is an array of 10 components of type int. Which of

ID: 3582236 • Letter: 5

Question

57) In C++:

Suppose that list is an array of 10 components of type int. Which of the following codes correctly outputs all the elements of list?

for (int j = 1; j < 10; j++)
  cout << list[j] << " ";
cout << endl;

for (int j = 1; j <= 10; j++)
  cout << list[j] << " ";
cout << endl;

for (int j = 0; j <= 9; j++)
  cout << list[j] << " ";
cout << endl;

for (int j = 1; j < 11; j++)
  cout << list[j] << " ";
cout << endl;

a.

for (int j = 1; j < 10; j++)
  cout << list[j] << " ";
cout << endl;

b.

for (int j = 1; j <= 10; j++)
  cout << list[j] << " ";
cout << endl;

c.

for (int j = 0; j <= 9; j++)
  cout << list[j] << " ";
cout << endl;

d.

for (int j = 1; j < 11; j++)
  cout << list[j] << " ";
cout << endl;

Explanation / Answer

C is the right answer

intiger array starts with 0 the element

So in the 10 element array is

list[0], list[1], list[2],.......list[9].

for(int j=0;j<=9;j++)//loop from0 to 9

cout<<list[j]<<" "; //prints j th element and space

cout << endl;

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