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

Answers

Answer 1
Answer:

Answer:

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


Related Questions

Which of the following statements is not true?A. A structured chart is a sequential representation of program designB. the Real-Time system is a particular case of a on-line-systemC. Batch totals are not incorporated while designing real-time applicationsD. 4GLs are used for application proto typingE. None of the above
Write a program that reads a list of words. Then, the program outputs those words and their frequencies. If the input is 5 hey hi Mark hi mark (the first number indicates the number of words that follow), the output is:hey 1hi 2Mark 1hi 2mark 1Hint: Use two vectors, one for the strings, another for the frequencies.Your program must define and use the following function: int GetFrequencyOfWord(vector wordsList, string currWord)
Write a statement that assigns total_coins with the sum of nickel_count and dime_count. Sample output for 100 nickels and 200 dimes is: 300
Why is a bedroom considered a poor study environment?Bedrooms are dimly lit.Bedrooms are too small.Bedrooms are too comfortable.Bedrooms are messy and cluttered.
Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 2, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by " seconds". End with a newline.

Write a C++ program to find the number of pairs of integers in a given array of integers whose sum is equal to a specified number.

Answers

Answer:

int main()

{

   int A1= {5,3,4,8,9,0,7};

   int SArri1 = sizeof(A1);

  printf("Original array: ");

   

   for (int i=0; i < SArri1;i++)  

   printf("", A1[i] );

   

   int i, sum = 20, n= 0;

   printf("\nArray pairs whose sum equal to 20: ");

   

   for (int i=0; i<SArri1; i++)

       for (int j=i+1; j<SArri1; j++)

           if (A1[i]+A1[j] == sum)

             {

              Printf(“\n”, array1[i])

Printf(“,”,array1[j]);

               n++;

             }

 

  printf("\nNumber of pairs whose sum equal to 20: ",n)

   return 0;

}

Explanation:

First of all, you should create the array of integers, and put random numbers. Then you have to save in a constant the size of the array (in this  code is called SArr1) With a for you can print all the numbers that are on the array because then you will print all array pairs whose sum is equal to  a specified numer. in this code we are going to use 20.

then with a condition (if) you are going to compare one of number of the array with all the others and check if its equal to 20. If yes, it going to print the numbers that answer to that condition and it's going to add +1 to the variable n (for this you will need to use two bucles for)

Then you can print the number of pairs whose sum is equal to 20 by printing n

Write a statement that defines an array of four integers named miles. The array should be initialized with the values 1, 5, 9, and 22.

Answers

Answer:

int miles[4] = {1, 5, 9, 22};

Explanation:

Given:

Initialized values = 1, 5, 9, and 22

Find:

Defines an array of four integers

Computation:

int miles[4] = {1, 5, 9, 22};

Write a program (main method) that advises the user on programming language. So if a user for instance enters "Java" the program might say "awesome" or if the user enters "Ruby" it might say "are you sure?" . Make the program comment on at least 5 programming languages.

Answers

import java.util.Scanner;

public class JavaApplication41 {

   

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       String language = scan.nextLine();

       if (language.toLowerCase().equals("java")){

           System.out.println("Awesome!");

       }

       else if (language.toLowerCase().equals("python")){

           System.out.println("A very simple language!");

       }

       else if (language.toLowerCase().equals("ruby")){

           System.out.println("Are you sure?");

       }

       else if (language.toLowerCase().equals("javascript")){

           System.out.println("Easy enough");

       }

       else if (language.toLowerCase().equals("c")){

           System.out.println("Cool!");

       }

   }

   

}

I hope this helps!

Suppose that each country completely specializes in the production of the good in which it has a comparative advantage, producing only that good. Inthis case, the country that produces rye will produce million bushels per week, and the country that produces jeans will produce

million pairs per week.

Answers

Answer:

In  this case, the country that produces rye will produce 24 million bushels per week, and the country that produces jeans will produce 64  million pairs per week.

Explanation:

Total labor hour = 4 million hour

Number of bushes produce in 1 hour = 6

⇒total bushes produce = 6*4 = 24 million

∴ we get

The country that produces rye will produce 24 million bushels per week

Now,

Total labor hour = 4 million hour

Number of pairs produce in 1 hour = 16

⇒total bushes produce = 16*4 = 64 million

∴ we get

The country that produces jeans will produce 64  million pairs per week.

How many times will the following loop display "Looping again!"? for(int i=0; i<=20; i++) cout << "Looping again!" << endl;

Answers

Answer:

21 times

Explanation:

Following are the description of output:

  • As it is for loop and The loop is started from the i=0 , after that check the condition 0<=20 condition is true .The control moves to the body of loop and it print Looping again! on the console window .After that it increment the value of i=i+1 .
  • Now i=1  1<=20  condition is true .The control moves to the body of loop and it print Looping again! on the console window .After that it increment the value of i=i+1 .
  • i=2 2<=20 condition is true .The control moves to the body of loop and it print Looping again! on the console window .After that it increment the value of i=i+1 .
  • ............soon
  • This process is executed again and again but when the value i=21 the loop condition is false .The loop is terminated .
  • As the loop is starts from the i=0 and executed less then equal to 20 therefore 21 times the loop is executed .

Suppose that a queue is implemented using a circular array of size 12. What is the value of last after the following operations?10 enqueue operations
5 dequeue operations
6 enqueue operations
10 dequeue operations
8 enqueue operations
2 dequeue operations
3 enqueue operations
Last = 10

Answers

Answer:

10

Explanation:

An enqueue operation is a function that adds an element(value) to a queue array. A dequeue operations removes an element from a queue array. Queue arrays follow a first-in-first-out approach, so elements that are first stored in the queue are removed/accessed first(enqueue operations add elements at the rear of the queue array).

The following operations leave 10 elements in the queue of array size 12 after its done:

10 enqueue operations= adds 10 elements

5 dequeue operations= removes 5 elements( 5 elements left in queue)

6 enqueue operations= adds 6 elements(11 elements in queue)

10 dequeue operations= removes 10 elements(1 element left in queue)

8 enqueue operations= adds 8 elements(9 elements in queue)

2 dequeue operations= removes 2 elements(7 elements left in queue)

3 enqueue operations= adds 3 elements(10 elements in queue)

Therefore there are 10 elements in the queue after enqueue and dequeue operations.