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
You have $200 in a savings account. Each week for 8 weeks, you take put $18 for spending money. How much money is on your accoun
IceJOKER [234]

8 * 18 = 144

200 - 144 = 56

so $56 dollars would be left in your bank account

8 0
3 years ago
Read 2 more answers
L1 : (-1, 4) and (3, 4) L2: (3, 5) and (3, 0) A. Parallel B. Perpendicular C. Neither
satela [25.4K]

answer for this question is (b)perpendicular

7 0
3 years ago
What level of measurement is a person's "favorite sport"? A. Interval B. Nominal C. Ratio D. Ordinal
tiny-mole [99]

Answer:

(B), Nominal.

Step-by-step explanation:

A nominal or categorical scale of measurement that is generally used to label or categorize the variables.

The person's "favorite sport" depicts the nominal scale of measurement.

Hence, the correct option is (B), Nominal.

4 0
3 years ago
In her metalwork class, Anja cut a square of
Paul [167]

Given:

Anju cut square of tin, of edge 3.7 cm, from a larger square of edge 6.3 cm.

To find:

The area of the remaining tin.

Solution:

Area of a square is:

Area=a^2

Where, a is the edge of the square.

Area of the smaller square is:

A_1=(3.7)^2

A_1=13.69

Area of the larger square is:

A_2=(6.3)^2

A_2=39.69

The area of the remaining tin is:

A=A_2-A_1

A=39.69-13.69

A=26

Therefore, the area of the remaining tin is 26 sq. cm.

8 0
2 years ago
A company rents riding equipment for a fixed amount plus a fee based on the number of days for which the equipment is rented. Th
nikklg [1K]
The answer is 6. I know that because I solved the question and I got 6 I'm positive its 6. Hope this helps.
7 0
3 years ago
Read 2 more answers
Other questions:
  • Which linear inequality is represented by the graph?
    12·1 answer
  • Help quick!!!!! be original
    6·1 answer
  • Use the properties of exponents to rewrite the expression.<br> 5e•5e•5e•5e
    6·1 answer
  • PLS HELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    13·1 answer
  • What percent of the values are between 10 and 30? Round to the nearest tenth of a percent if necessary.
    9·1 answer
  • A circle's radius is increased by 10%. By what percentage does its area increase
    12·1 answer
  • Emily has 27 Barbie dolls. She put equal number of dolls in each of 5 boxes. How many dolls are left over?
    10·1 answer
  • Give the dregree for the polynomial
    8·1 answer
  • Simplify this radical expression → 3√24​
    7·1 answer
  • Only 12 people can ride a trolley at one time. This is 20% of the people waiting to ride. How many people are waiting to ride?​
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!