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
Asap!! someone please help! i don't understand how graphing functions work
KATRIN_1 [288]
The first graph is B.  x^2 + 6 < 3
It is a parabola and opens upward when x^2 is positive.  6 raises it upwards by 6 units.  the circle at
x = 3 means that the function can approach but not be equal to 3.
3 0
3 years ago
What is the length of the diagonal (d) in the solid below?
Cerrena [4.2K]
The length would be 12
8 0
3 years ago
Read 2 more answers
The formula a = 118e0.024t models the population of a particular city, in thousands, t years after 1998. when will the populatio
andriy [413]
Given that the population has been modeled by the formula:
a=118e^(0.024t), the time taken for the population to hit 140k will be given by:
140000=118e^(0.024t)
solving for t we shall have:
140000/118=e^(0.024t)
thus;
0.024t=ln(140000/118)
t=1/0.024*ln(140000/118)
t=295
thus the time the population will be 140000 will be:
1998+295
=2293
6 0
3 years ago
It took the Selby family hours round -trip to drive from their house to their beach house 154 miles away . Find their average sp
seropon [69]

Step-by-step explanation:

Distance = 154 miles .

Time = 5 ½ hrs .

We know ,

Speed = s / t

v = 154 mi/ 5.5 hrs = 28 mi / hr

3 0
2 years ago
What is 27 minus 3.204 minus 10.8
lawyer [7]
   27
- 3.204
  10.8
----------

12.996 ?

6 0
3 years ago
Read 2 more answers
Other questions:
  • How do you write an equation to represent a real-world situation?
    11·1 answer
  • Find two consecutive positive even numbers
    15·1 answer
  • Which values are solutions of the quadratic equation 0 = (x + 3)2 – 4? Check all that apply.
    5·1 answer
  • What two integers dors √7,fall between
    8·1 answer
  • What is the pecentage of 123 of 300
    14·2 answers
  • 35•7 to the 3rd power
    11·1 answer
  • What is the gcf for 18m 45mn?
    11·2 answers
  • Tomic and Brooke make a game of shooting free throws. Each basket is worth 2 points. Each miss is worth
    15·2 answers
  • Timed Test Please Help.
    6·1 answer
  • 2. Tell whether the lines through the given points are parallel, perpendicular,
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!