Ask Question
6 March, 00:55

Suppose that a is declared as an int a[99]. Give the contents of the array after the following two statements are executed: for (i = 0; i <99; i++) a[i] = a[a[i]];

+3
Answers (1)
  1. 6 March, 04:53
    0
    Each array position holds the position from which the information is going to be retrieved. After the code is run, each position will have the information retrieved from that position.

    Explanation:

    The best way to solve this problem is working as if we had a very small array. Then we can generalize for the large array.

    For example

    int a[3];

    a[0] = 1; a[1] = 2; a[2] = 0;

    for (i = 0; i < 3; i++)

    a[i] = a[a[i]];

    When i = 0, we have:

    a[i] = a[a[i]] = a[a[0]] = a[1] = 2;

    When i = 1, we have

    a[i] = a[a[i]] = a[a[1]] = a[2] = 0;

    When i = 2, we have

    a[i] = a[a[i]] = a[a[2]] = a[0] = 1;

    Basically, in our small example, each array position holds the index from which we are going to retrieve the information. The same is going to happen in the array of length 99. After the code is run, each position will have the information retrieved from that position
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Suppose that a is declared as an int a[99]. Give the contents of the array after the following two statements are executed: for (i = 0; i ...” 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