Ask Question
28 November, 20:52

R7.1 Carry out the following tasks with an array:

(A) Allocate an array a of ten integers.

(B) Put the number 17 as the initial element of the array.

(C) Put the number 29 as the last element of the array.

(D) Fill the remaining elements with â€"1.

+5
Answers (1)
  1. 28 November, 23:38
    0
    Following are the program in the C+ + Programming Language.

    //set header file or namespace

    #include

    using namespace std;

    //define main function

    int main () {

    //set integer type array with indexing 10

    int a[10];

    //set integer type variable to 1

    int i=1;

    //set element in 1st index

    a[0]=17;

    //set element in last index

    a[9]=29;

    //set while loop for the remaining elements

    while (i<9)

    {

    //set - 1 in the remaining elements

    a[i]=-1;

    i++;

    }

    //set for loop to print array

    for (int j = 0; j < 10; j++) {

    cout << a[j]<
    }

    }

    Output:

    17

    -1

    -1

    -1

    -1

    -1

    -1

    -1

    -1

    29

    Explanation:

    In the following program, we define the main function "main () " and inside it.

    Set an integer type array element "a[]" with index value 10. Set integer data type variable "i" initialize to 1. Set elements in the first and last place in the array. Set the while loop to initialize elements for the remaining place. Set the for loop to print the array elements.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “R7.1 Carry out the following tasks with an array: (A) Allocate an array a of ten integers. (B) Put the number 17 as the initial element of ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers