1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
horrorfan [7]
3 years ago
12

Suppose that a is a one-dimensional array of ints with a length of at least 2. Which of the following code fragments successfull

y exchange(s) the values of the first two elements of a?I a[ 0 ] = a[ 1 ];a[ 1 ] = a[ 0 ];II int t = a[ 0 ];a[ 0 ] = a[ 1 ];a[ 1 ] = t;III a[ 0 ] = a[ 0 ] - a[ 1 ];a[ 1 ] = a[ 0 ] + a[ 1 ];a[ 0 ] = a[ 1 ] - a[ 0 ];A) I onlyB) II onlyC) III onlyD) I and II onlyE) II and III only
Mathematics
1 answer:
elixir [45]3 years ago
6 0

Answer:

E)II and III only

Step-by-step explanation:

This can be seen with examples. Say a[0]=1 and and a[1]=2.

for I , the first line of code would be:

a[0]=a[1];

thus, we would get a new value for a[0]=2.

The second line of code

a[1]=a[0]; uses the new value of a[0], so we would get a[1]=2.

The end result is a[0]=2, and a[1]=2 which doesn't exchange the values of the first two elements.

For II the first line of code

int t= a[0]; saves the original value of a[0] to t, so we get t=1.

the second line of code

a[0]=a[1]; changes the value of a[0]  to that of a[1]. Thus, in our example a[0]=2.

the final line

a[1]=t; changes the value of a[1] to the original value of a[0], giving us a[1]=1 and a[0]=2, what we were looking for.

For III

the first line of code

a[0]=a[0]-a[1];

gives us

a[0]=1-2

the secon line

a[1]=a[1]+a[0];

takes the new value of a[0] and replaces it in the expression

a[1]= 2+(1-2)=1

the last line

a[0]=a[1]-a[0];

takes the new value of a[0] and a[1] and replaces the in the expression

a[0]=1-(1-2)=1-1+2=2

which exchanges the values needed.

So we can see that only II and III do what we require, giving us E as the answer.

You might be interested in
Diane purchased a prepaid phone card for $15. Long distance calls cost 17 cents a minute using this card. Diane used her card on
tester [92]

Answer:

22 minutes

Step-by-step explanation:

15-11.26=3.74

3.74 divided by .17 eqauls 22

8 0
3 years ago
Greg's long jump measured 5 2/3 feet. Peter's long jump measured 6 3/4 feet. How many feet did the two boys jump altogether?
Len [333]

Answer:

12.41 or 12 5/12

Step-by-step explanation:

add 5.66+6.75=12.41

or 5 2/3 +6 3/4, get common denominator which is 12, then divide to get 5 8/12 +6 9/12= 11 17/12 or 12 5/12

5 0
3 years ago
A paint mixture was formed by mixing exactly 3 colors of paint. By volume, the mixture was x% blue paint, y% green paint, and z%
sergeinik [125]

Answer:

Both statements are sufficient to answer the question

Step-by-step explanation:

Given:

- The paint mixture has following proportions:

 Total volume of paint = T

 Blue:  x*T / 100

 Green: y*T/100

 Red: z*T/100

Find:

Statement 1: x = y

Statement: z = 60

Which of the above statement is sufficient to calculate the amount of green paint used

Solution:

Statement 1:

- The amount of blue paint used is:

                    1 gallon = x*T / 100

- x = y,

                    1 gallon = y*T / 100

Hence,

                    Amount of green paint used is 1 gallon

- The statement is sufficient

Statement 2:

- The amount of red paint used is:

                    3 gallon = z*T / 100

                    T = 300 / z = 300 / 60 = 5 gallons

                    T = R + B + G

                    G = T - R - B

                    G = 5 - 3 - 1

                    G = 1 gallons

Hence,

                    Amount of green paint used is 1 gallon

- The statement is sufficient

5 0
3 years ago
What is3/4 - 1/2 and what is 7/8-2/3
Mariulka [41]
3/4 - 1/2 = 3/4 - 2/4 = 1/4

7/8 - 2/3 = 21/24 - 16/24 = 5/24
7 0
3 years ago
there are 100 movies at the store 30/100 are action movies 50/100 are comedies and 20/100 are adventure movies what part of the
pogonyaev

Answer:30 action and 50 comedies which is 80/100 or 80%/100%

Step-by-step explanation:

8 0
3 years ago
Other questions:
  • Complete the square for 2x^2-4x=14
    6·2 answers
  • I need duh helpssssssssssss
    11·1 answer
  • Find at least 10 solutions to the linear equation 3x+y=-8​
    13·1 answer
  • Armando bought 45 baseball cards. of the 12 friends he invited to his cookout, half of them were able to attend. armando gave ea
    15·2 answers
  • Please please help 30 points
    12·1 answer
  • If there is a 60% chance of rain tomorrow and a 40% chance of wind and rain,
    15·2 answers
  • 3x over 2x-6 plus 9 over 6-2x
    8·2 answers
  • Find the value of y...​
    13·1 answer
  • Marissa just bought 100 acres of land. She wants to grow apple, peach, and cherry trees on her land. Color the model to show how
    15·2 answers
  • Please help with algebra
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!