Question: Use the nums array to answer. The array was declared using the int nums[4] = {10, 5, 7, 2}; statement. The x and total variables
Use the nums array to answer. The array was declared using the int nums[4] = {10, 5, 7, 2}; statement. The x and total variables are int variables and are initialized to 0. The avg variable is a double variable and is initialized to 0.0.
Which of the following will correctly calculate the average of the elements included in the nums array?
a. while (x < 4)
{
nums[x] = total + total;
x += 1;
} //end while
avg = static_cast(total) /
static_cast(x);
b. while (x < 4)
{
total += nums[x];
x += 1;
} //end while
avg = static_cast(total) /
static_cast(x);
c. while (x < 4)
{
total += nums[x];
x += 1;
} //end while
avg = static_cast(total) /
static_cast(x);
c. while (x < 4)
{
total += nums[x];
x += 1;
} //end while
avg = static_cast(total) /
static_cast(x) – 1;
d. while (x < 4)
{
total += nums[x];
x += 1;
} //end while
avg = static_cast(total) /
static_cast(x - 1);
Step by Step Solution
3.46 Rating (166 Votes )
There are 3 Steps involved in it
b while x 4 tot... View full answer
Get step-by-step solutions from verified subject matter experts
