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
PLEASE HELP!!!<br><br> Which line is the best model for the data in the scatter plot?
fomenos

Answer:

top left

Step-by-step explanation:

it goes through the most dots

8 0
3 years ago
Triangle MNO is an equilateral triangle with sides measuring units. What is the height of the triangle? a) 12 units b) 24 units
Alecsey [184]

Answer:

The height of the equilateral triangle is 24 units

Step-by-step explanation:

In the question above, the unit of the side of the equilateral triangle is not given. If the complete question is:

Triangle MNO is an equilateral triangle with sides measuring 16 square root of 3 units, then the length of each side is 16√3 units.

To find the height of the triangle, we use Pythagoras theorem

MP^2 + PO^2 = MO^2

Let MP^2 be x

x^2 + {(16√3)/2}^2 = (16√3)^2

X^2 + (256*3)/4 = 256*3

4x^2 + 768 = 768* 4

4x^2 + 768 = 3072

4x^2 = 3072-768

4x^2 = 2304

X^2 = 2304/4

X^2 = 576

x= √576

x = 24 units

4 0
3 years ago
Read 2 more answers
2(x+x+12) &gt; 100 (why does the 20 character thing exist)
arlik [135]

Answer:

x > 19

Step-by-step explanation:

2(x+x+12) > 100

 2(2x+12) > 100

     4x+24 > 100

           4x > 76

              x > 19

3 0
3 years ago
Given: ABCD is a trapezoid, m∠1=m∠2, m∠3=m∠4, AB = CD, AC ∩ BD = O <br> Prove: m∠AOD = m∠BCD
LiRa [457]
Since AB = CD the trapezoid is isosceles, which means that ∡A = ∡D

Therefore also ∡2 = ∡3 (they are half of the congruent angles)

For the properties of parallel lines (BD and AD) crossed by a transversal (BD) we have ∡3 = ∡CBD.

Now consider triangles AOD and BCD:
∡OAD (2) = ∡ADO (3) = ∡CBD (3) = ∡CDB (4)

T<span>he sum of the angles of a triangle must be 180°, t</span>herefore:
∡AOD = 180 - ∡2 - ∡3
∡BCD = 180 - ∡3 - ∡4

∡AOD = ∡BCD because their measure is the difference of congruent angles.

6 0
3 years ago
(story problem) Michael and Sally went to get ice cream after school. each of them brought an ice cream for $3.55, a bottle of w
Tcecarenko [31]
2(3.55+2.25+.55+2.30)= 17.30+2.30=19.60
7 0
3 years ago
Other questions:
  • Need help pls asap. 40 points
    14·1 answer
  • Need help with 26 &amp; 27
    8·1 answer
  • What is the degree of this polynomial ? X^2+12x36
    14·1 answer
  • 4 is the square root of which number ?
    9·1 answer
  • Please help <br><br>the question is beloww
    13·1 answer
  • What would y equal for this isosceles triangle
    10·2 answers
  • Which of the following is the equation of the line that passes through the point begin ordered pair, negative 6, 1, end ordered
    5·1 answer
  • A rectangular prism has a volume of 80 m3. What is the length of the rectangular
    13·2 answers
  • Lewis scored 0.15 of the points in a basketball game. How many of the team's 120 points did Lewis score
    7·1 answer
  • I don't really get this the one on the bottom but you use the top to solve
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!