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 answer to 8 + y = 4x must show work
Scrat [10]

To find the x-intercept, substitute in  0  for  y  and solve for  x . To find the y-intercept, substitute in  0 for  x

and solve for  y .

x-intercept:  ( 2 , 0 )

y-intercept:  ( 0 , − 8 )

7 0
3 years ago
Read 2 more answers
Solve each system by elimination by multiplying both equations. eliminate y first. show all work.
Alex17521 [72]
First \mathrm{Multiply\:}10x-3y=18\mathrm{\:by\:}3:\quad 30x-9y=54
Then \mathrm{Multiply\:}6x-10y=-22\mathrm{\:by\:}5:\quad 30x-50y=-110
To get \begin{bmatrix}30x-9y=54\\ 30x-50y=-110\end{bmatrix}
So...
30x-50y=-110 \ \textgreater \  \begin{bmatrix}30x-9y=54\\ -41y=-164\end{bmatrix}
-41y=-164 \ \textgreater \  \mathrm{Divide\:both\:sides\:by\:}-41 \ \textgreater \  \frac{-41y}{-41}=\frac{-164}{-41}
To get y = 4.
\mathrm{For\:}30x-9y=54\mathrm{\:plug\:in\:} \:y=4 \ \textgreater \  30x-9\cdot \:4=54
\mathrm{Multiply\:the\:numbers:}\:9\cdot \:4=36 \ \textgreater \  30x-36=54 \ \textgreater \
Next \mathrm{Add\:}36\mathrm{\:to\:both\:sides} \ \textgreater \  30x-36+36=54+36 \ \textgreater \  \mathrm{Simplify} \ \textgreater \  30x=90
Finally \mathrm{Divide\:both\:sides\:by\:}30 \ \textgreater \  \frac{30x}{30}=\frac{90}{30} \ \textgreater \  x = 3
Therefore our solutions are y = 4, x = 3
8 0
3 years ago
1/3x = 6 what is the letter x
Cloud [144]

Answer:

18

Step-by-step explanation:

Solve for  x  by simplifying both sides of the equation, then isolating the variable.

6 0
3 years ago
Read 2 more answers
What does it mean for statements to be logically equivalent?
nlexa [21]

Answer:

Two statement forms are called logically equivalent if they have identical truth values for each possible substitution for their statement variables.

Step-by-step explanation:

hope this helps <333

brainliest plz :) ?

8 0
3 years ago
Which equation represents a line that passes through (2,-1/2) and has a slope of 3?
krok68 [10]

Answer:

the 3rd one

Step-by-step explanation:

3 0
3 years ago
Read 2 more answers
Other questions:
  • Find the factorization of the polynomial below.
    13·2 answers
  • How do you solve ky-bf=fy/m?
    12·1 answer
  • What is the solution to the system of equations?
    10·1 answer
  • Help me complete this
    13·1 answer
  • PLS HELP ME ASAP!!!<br><br> PLSSSSSSSSSSSSSSSSSSSSSSSS!
    12·1 answer
  • Find the coefficient of the third term in the expansion of (2x+y)^5
    6·1 answer
  • What is the volume of this figure? Pls help this is due Thursday 11:45
    6·1 answer
  • I need help on this please
    10·1 answer
  • Consider this polynomial: 8kn+2k^7-9k-8n+3n^7
    9·1 answer
  • If 10 plastic bowls cost $7.60 and the price of each bowl is the same, how much does each bowl cost?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!