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
What is the area of the pentagon shown? 16 cm 15 cm 18 cm 20 cm 360 cm2 354 cm2 300 cm2 297 cm2​
nexus9112 [7]
U need upload the image
6 0
3 years ago
1000ml:300ml to its simplest form
Diano4ka-milaya [45]
<h2>HI MATE YOUR ANSWER SHOULD BE 10/3</h2>
5 0
2 years ago
Nathan has a collection of 220 baseball cards. He lets his brother 1/4 of his collection and sells 20% of his collection to the
tatyana61 [14]

<u>Answer:</u>

The baseball cards remain in Nathan’s collection is 106 cards

<u>Explanation:</u>

Total number of cards Nathan has= 220

Number of cards he let his brother have = 1/4 of his collection

=\frac{1}{4} \times 220 = 55 cards

Number of cards he sells = 20% of his collection

=\frac{20}{100} \times 220

=44 cards

No of cards he gives to his friends=15 cards

Remaining cards = total number of cards – (no of cards he gave to his brother+ cards he sold+ cards he gave to this friends)

= 220 – ( 55+44+15)

=220-114

=106 cards

baseball cards remain in Nathan’s collection is 106 cards

4 0
3 years ago
3/4 and 7/8 are equivalent fractions.<br> true or false?
ANTONII [103]
False 3/4 is smaller than 7/8
5 0
3 years ago
Read 2 more answers
Solve using the quadratic formula or factoring ... 5=6x^2 + 13x
FromTheMoon [43]

Answer:

x = \frac{-5}{2} <u><em>or  </em></u>x = \frac{-1}{3}

Step-by-step explanation:

5 − 6 2 − 1 3 = 0

− 6 2 − 1 3 + 5 = 0 -6x^2-13x+5=0 −6x2−13x+5=0 − 1

( 6 2 + 1 3 − 5 ) = 0

7 0
3 years ago
Read 2 more answers
Other questions:
  • Four less than the product of one and number x
    6·1 answer
  • What is the greatest possible integer solution of the inequality 3.829x &lt; 28.195?
    15·1 answer
  • Cressida decided to save a part of her income in a savings account that compounds interest every four months. Her account balanc
    13·2 answers
  • How do you write 701,245 in two forms
    6·2 answers
  • an object starts from rest and accelerates at a rate of 4 m/s^2 for 3 seconds. What is its displacement from the start position?
    11·1 answer
  • Need some help please
    6·2 answers
  • Crop researchers plant 15 plots with a new variety of corn. The yields in bushels per acre are: 138.0 139.1 113.0 132.5 140.7 10
    6·1 answer
  • Can i get some help? 30-60-90 triangle
    11·2 answers
  • Find the slope of the following line. Y=1.4x
    9·2 answers
  • Darius takes his family on an afternoon boat ride.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!