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
RSB [31]
3 years ago
7

What will be the values of ans, x, and y after the following statements are executed? int ans = 35, x = 50, y =50; if ( x >=

y) { ans = x + 10; x -=y; } else { ans = y + 10; y += x; } A. ans = 60, x = 50, y =100 B. ans = 60, x =0, y =50 C. ans = 45, x = 50, y = 0 D. ans = 45, x = 50, y = 50
Computers and Technology
2 answers:
Nutka1998 [239]3 years ago
6 0

Answer:

B. ans = 60; x = 0; y = 50

Explanation:

<em>(i)First format the code properly as follows:</em>

int ans = 35, x = 50, y =50;

if ( x >= y) {

ans = x + 10;

x -=y;

} else {

ans = y + 10;

y += x;

}

<em>(ii) Taking the if statement of the code;</em>

The if statement block is executed if x is greater than or equal to y (x >= y).

Since x=50 and y=50, then the code continues to execute the statement in the block.

In the if block;

(a) the first line is

<em>ans = x + 10. </em>

Since x = 50, substituting for x gives

ans = 50 + 10 = 60

Therefore <em>ans = 60</em>

(b) the second line is

<em>x -= y</em>

This can be re-written as

x = x - y.

This means that the value of x - y is written back into x. Therefore since x = 50 and y = 50, substituting for x and y gives

x = 50 - 50 = 0

Therefore <em>x = 0</em>

(c) the value of y is not changed at all, therefore <em>y = 50</em>

<em />

<em>(iii) Taking the else statement of the code;</em>

Since the if statement of the code has been executed, the else statement is simply skipped.

Therefore the final values of ans, x, y are respectively 60, 0 and 50

Hatshy [7]3 years ago
4 0

Answer:

B. ans = 60, x = 0, y = 50

Step wise Explanation of the code chunk

  • The first statement assigns value 35 to ans variable, value of 50 to x variable and value of 50 to y variable.
  • Next is an if statement which checks if the value of x variable is greater than or equal to y
  • This condition is true as x = 50 and y = 50 So x = y
  • Now since the statement is true it will enter the if block of the code which is the instruction: ans = x + 10; x -=y; and ignores the else block.
  • This line changes the value of ans variable and assigns it the value obtained by adding 10 to the value of variable x.
  • we know that         x = 50

        So

                                      ans = x + 10

                                      ans = 50 + 10

                                          ans = 60

  • After this, comes another line x -=y; which means decrement the value of x by value of y

that means:

                                              x = x - y

                                              x = 50-50

                                                  x = 0

  • So the new value of ans is 60, new value of x is 0 and the value of y remains the same i.e. 50

Hence

                                                ans = 60

                                                    x  =  0

                                                    y  = 50

                                     

You might be interested in
How can you tell if a website is biased?
Leona [35]

Answer:

the author has not considered other points of view.

7 0
2 years ago
Did it go from a sail boat to a row boat or vise versea
Bingel [31]
A sail boat went to a row boat.
8 0
3 years ago
Given the following table of students, assignments, and grades for a single class:
PilotLPTM [1.2K]

Answer:

i need more

Explanation:

i need more

7 0
3 years ago
True or False: The term whitespace speaks to the design of a website
prisoha [69]

Answer:

True

Explanation:

I took the test a little while ago

7 0
4 years ago
Read 2 more answers
Does any one know how to get an image from another site pasted onto this site?
elixir [45]
You're not supposed to copy things from other sites so it won't be easy to do. But you can save the image to your computer then upload it here using the paperclip icon. 
3 0
3 years ago
Other questions:
  • Your friend sends you a photograph of his son. you want to enlarge the photograph. which program type will you use to make this
    15·1 answer
  • The software used to help run the computer hardware is the _____.
    9·2 answers
  • A cache has been designed such that it has 512 lines, with each line or block containing 8 words. Identify the line number, tag,
    7·1 answer
  • All of the following can be caused by the movement of geologic plates EXCEPT
    15·1 answer
  • 29 POINTS!!!
    6·1 answer
  • Why are computers complicated?
    15·1 answer
  • Please please help I don’t understand this please.
    11·1 answer
  • An electronics company develops a line of augmented reality headsets for use in interactive 3d media applications using 5g mmwav
    7·1 answer
  • Question 8 of 10
    5·1 answer
  • Question in file i need this work done tonight
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!