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
Ahmed found the volume of a cone having both a height and a diameter of 6 centimeters. His work is shown below. Step 1 Find the
kaheart [24]

Answer:

C- step 3, the resulting area should be in terms of pi

Step-by-step explanation:

I did the test on edge, I passed

8 0
2 years ago
Read 2 more answers
What is the risk of going into a group of more than 20 or more people at this time from coronavirus?
olga55 [171]

Answer:

Even if a person doesn't show symptoms, they can still have it.

Step-by-step explanation:

That's the problem.

Even if you think everyone isn't sick, they very well could be, and because there is no vaccine and it spreads so quickly, there's a chance that all the people in that group could get it.

5 0
3 years ago
Read 2 more answers
Does anybody know this answer?
creativ13 [48]

Answer:

circumference=2πr

=2×3.14×8.5

=53.38cm

7 0
2 years ago
Read 2 more answers
Help with 5b please . thank you.​
Allushta [10]

Answer:

See explanation

Step-by-step explanation:

We are given f(x)=ln(1+x)-x+(1/2)x^2.

We are first ask to differentiate this.

We will need chain rule for first term and power rule for all three terms.

f'(x)=(1+x)'/(1+x)-(1)+(1/2)×2x

f'(x)=(0+1)/(1+x)-(1)+x

f'(x)=1/(1+x)-(1)+x

We are then ask to prove if x is positive then f is positive.

I'm thinking they want us to use the derivative part in our answer.

Let's look at the critical numbers.

f' is undefined at x=-1 and it also makes f undefined.

Let's see if we can find when expression is 0.

1/(1+x)-(1)+x=0

Find common denominator:

1/(1+x)-(1+x)/(1+x)+x(1+x)/(1+x)=0

(1-1-x+x+x^2)/(1+x)=0

A fraction can only be zero when it's numerator is.

Simplify numerator equal 0:

x^2=0

This happens at x=0.

This means the expression,f, is increasing or decreasing after x=0. Let's found out what's happening there. f'(1)=1/(1+1)-(1)+1=1/2 which means after x=0, f is increasing since f'>0 after x=0.

So we should see increasing values of f when we up the value for x after 0.

Plugging in 0 gives: f(0)=ln(1+0)-0+(1/2)0^2=0.

So any value f, after this x=0, should be higher than 0 since f(0)=0 and f' told us f in increasing after x equals 0.

8 0
2 years ago
Nad podaną liczba wpisz liczbę 2 razy większa a pod nią 2 razy mniejsza
zepelin [54]
Sorry but I can't understand your language
3 0
3 years ago
Other questions:
  • What is the GFC of 28 and 35
    8·2 answers
  • Marco walked 27/100 kilometers to the park. Then he walked 3/10 kilometers to the library. What fraction of a kilometer did he w
    14·1 answer
  • Find the interest in dollars and the proceeds for the following problem. Choose the right answers. John Green received a $580 di
    6·2 answers
  • Need help solving for X
    5·1 answer
  • PLEASE HELP!!!!!!! IM BEING TIMED
    9·1 answer
  • Jason gets paid $75 for 5 hours of lawn mowing. Jeremy mows lawns for 8 hours and is paid $160. What is the difference between t
    10·1 answer
  • Emily convinced her mom to buy a giant box of her favorite cereal. Her mom doesn't think the box will fit on
    14·1 answer
  • May u give all the answers to these? please and thank you! <3
    8·1 answer
  • Please help help please
    12·1 answer
  • Write 60/105 in its simplest form.
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!