80.7k views
9 votes
Write a program that uses an initializer list to store the following set of numbers in an array named nums. Then, print the array. 14 36 31 -2 11 -6 Sample Run [14, 36, 31, -2, 11, -6] (In edhesive please)

Write a program that uses an initializer list to store the following set of numbers-example-1

2 Answers

11 votes

Answer:

nums=[14, 36, 31, -2, 11, -6]

print(nums)

Step-by-step explanation:

I got a 100%

User Ajiri
by
4.7k points
8 votes

Answer:

In C++:

#include <iostream>

using namespace std;

int main(){

int nums[6] = {14, 36, 31, -2, 11, -6};

cout<<"[";

for(int i = 0;i<6;i++){

cout<<nums[i];

if(i != 5){cout<<", ";}

}

cout<<"]";

return 0;

}

Step-by-step explanation:

This initializes the array

int nums[6] = {14, 36, 31, -2, 11, -6};

This prints the opening square bracket

cout<<"[";

This iterates through the array

for(int i = 0;i<6;i++){

This prints individual elements of the array

cout<<nums[i];

Until the last index, this line prints comma after individual array elements

if(i != 5){cout<<", ";}

}

This prints the closing square bracket

cout<<"]";

User Whizcreed
by
4.8k points