Ask Question
10 October, 05:09

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]];

+4
Answers (1)
  1. 10 October, 08:43
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers