QUESTION 17
Suppose that sales is an array of 50 elements of type float. Which of the following correctly initializes the array
sales?
1. for (int 1 = 1; j <= 49; j++)
sales[j] = 0;
2. for (int j = 1; j <= 50; j++)
sales[j] = 0;
3. for (int j = 0; j <= 49; j++)
sales[j] = 0.0;
4. for (int j = 0; j <= 50; j++)
sales[j] = 0.0;
QUESTION 18
Suppose that list is an array of 10 elements of type int. Which of the following codes correctly outputs all the elements
of list?
1. for (int j = 1; j < 10; j++)
cout << list[j] << " ";
cout << endl;
2. for (int j = 0; j <= 9; j++)
cout << list[j] << " ";
cout << endl;
3. for (int j = 1; j < 11; j++)
cout << list[j] << " ";
cout << endl;
4. for (int j = 1; j <= 10; j++)
cout << list[j] << " ";
cout << endl;
Solution 17: Option [3] is the corect answer.
for (int j = 0; j <= 49; j++)
sales[j] = 0.0;
Slolution 18: Option [2] is the correct option.
2. for (int j = 0; j <= 9; j++)
cout << list[j] << " ";
cout << endl;
However, the above statement should be written more correctly as below:
2. for (int j = 0; j <= 9; j++)
{
cout << list[j] << " ";
cout << endl;
}
Comments
Leave a comment