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
A person's height is 5-ft 3-in. Their shadow has a length of 3-ft 6-in. If a nearby tree has a shadow of length 10-ft 4-in, what
Alchen [17]

Answer: The height of tree = 15 ft. 6 inches

Step-by-step explanation:

Given: A person's height is 5-ft 3-in = [5 x (12 )+3 ]  inches    [ 1 ft= 12 inches]

= 63 inches      

Their shadow has a length of 3-ft 6-in = [3 x 12+6] inches    

= 42 inches

If a nearby tree has a shadow of length 10-ft 4-in = [10 x 12+4] inches

= 124 inches.

At the same time,

\dfrac{\text{Height of tree}}{\text{Height of person}}=\dfrac{\text{Length person's shadow}}{\text{Length of tree's shadow}}\\\\\dfrac{\text{Height of tree}}{63}=\dfrac{124}{42}\\\\\Rightarrow\ \text{Height of tree}=\dfrac{124}{42}\times63=186\ inches\\\\=\dfrac{186}{12}= 15.5 ft\ or\ 15 ft.\ 6\ inches.

Hence, the height of tree = 15 ft. 6 inches

7 0
2 years ago
Adam and his dad share the cost of the meal in the ratio of 2:3.
lapo4ka [179]
52.20÷3= 17.40×5=87. The meal cost £87
6 0
3 years ago
Read 2 more answers
Show how you got y answers
trasher [3.6K]

Answer:

y = x - 3

Step-by-step explanation:

3x - 3y = 9

3x - 9 = 3y

x - 3 = y

y = x - 3

Then plug and chug for y by entering the given x values

3 0
3 years ago
The product of 5 and a number x is greater than 20<br> an inequality is ?<br> the solution is?
igor_vitrenko [27]

Answer:5*x>20

Step-by-step explanation: i think it is askinng to find x by comparing grater than less than

7 0
3 years ago
If x+1/x= 3 then x-1/x = ?
Alekssandra [29.7K]

Answer:

If x+1/x= 3 Then the answer for this equation (x-1/x=? ) will be...

Step-by-step explanation:

5 0
2 years ago
Other questions:
  • One line passes through the points (2,1) and (5,7). Another line passes through points (-3,8) and (8,3). Are the lines parallel,
    9·2 answers
  • What is the equation for the measure of Angle P?
    5·1 answer
  • Choose all the answers that apply. What is the freezing point of water? 0°C 0°F 32°C 32°F
    15·2 answers
  • What is the least common denominator of the equation StartFraction 2 Over 9 EndFraction x + two-thirds x = 7?
    15·1 answer
  • Help me please !!!!! Thanks
    6·1 answer
  • jesse bought a new video game system for 199.95 and three video games of 49.99 each. of the sale ta rate is 6.25%, how much tax
    11·1 answer
  • Find the value of Sin^-1(-√3/2)
    5·1 answer
  • Find the area of the triangle below, round your answer to the nearest hundredth.
    7·1 answer
  • Help pls i need help​
    12·1 answer
  • HELP PLEASE!!!!<br> THERE R 3 QUESTIONS. MAKE SURE TO ANSWER ALL 3!!!<br> TYSM
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!