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
Sarah's age is five less than twice her sister's age. Sarah is fifteen years old.
saul85 [17]
Let her sisters age be x.
=>sister .....x

Sarah.
twice x=2x. then less than 5
=> (2x-5 )
if Sarah = 15 years
by substation, 2x-5=15
3 0
3 years ago
Read 2 more answers
What is the volume? 7 mm 7 mm 7 mm cubic millimeters
Oksanka [162]

\Huge\bf\overbrace{\underline{ \underbrace{\blue \dag \orange{Answer}}}} \blue\dag

\large\bf\mapsto{\underline{\red{volume \: of \: cube =  {a}^{3} }}}

\huge\bf\mapsto{\underline{\green{  {7}^{3} }}}

\Large\bf\leadsto{\underline{\purple{ \: 7 \times 7 \times 7 = 343}}}

6 0
3 years ago
4.
valentinak56 [21]

Answer:

A

Step-by-step explanation:

<u>Slope- intercept </u><u>form</u>

y= mx +c, where m is the slope and c is the y-intercept.

The given equation is in the slope-intercept form and hence we can easily identify its slope by looking at the coefficient of x.

y= 2x +7

slope= 2

Parallel lines have the same slope, thus the slope of the parallel line is also 2.

Substitute m= 2 into the general equation:

y= 2x +c

Substitute a pair of coordinates into the equation to find the value of c:

When x= 3, y= 11,

11= 2(3) +c

11= 6 +c

c= 11 -6

c= 5

Therefore the equation of the line is y= 2x +5.

6 0
2 years ago
Read 2 more answers
What would you include on a list about physical activity?
mrs_skeptik [129]

Answer:

Walking and doing exercises

4 0
3 years ago
Need help with this asap
dem82 [27]

Answer:

I cant lie I don't know this answer

4 0
2 years ago
Read 2 more answers
Other questions:
  • Le
    6·1 answer
  • What is the answer to 3/2•5/4•7/3
    10·1 answer
  • Jane is making reusable grocery bags and lunch bags she needs 3/4 yard of material to make a grocery bag a lunch bag needs 2/3 o
    9·1 answer
  • If cost of 12 pens is ₹134, then what will be the cost of 5 such pen( please explain by method, don't answer directly)
    6·1 answer
  • What’s he answer to this
    10·1 answer
  • Explain how to write 3*3/8 as the product of a whole number and a unit fraction
    14·1 answer
  • 2466.075 rounded to the nearest hundredth
    7·1 answer
  • Which ordered pair describes a point that is located 4 units to the left of the origin and 2 units below the x-axis?
    14·1 answer
  • I need help quick it is due in 3 hours
    8·1 answer
  • Another easy one, Brainliest + 35 Points. per the usual
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!