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 much is a stock supra 1998​
saveliy_v [14]

Answer:

Hatchback Original MSRP / Price Engine

Supra 3dr LB Auto $31,078 / $29,122 6 Cylinder

Supra 3dr LB Sport Roof Auto $35,648 / $32,842 6 Cylinder

Supra 3dr LB Sport Roof Turbo Auto $38,778 / $35,903 6 Cylinder Turbo

Supra 3dr LB Sport Roof Turbo Manual $40,508 / $37,362 6 Cylinder Turbo

Explanation:

5 0
3 years ago
Which two factors mainly affect ocean tides on earth?
Troyanec [42]
Earths revolution about both the moon and the sun the moon the sun pull of distant planets
4 0
3 years ago
Please I need help with this !!!! <br> Complete the table given below.
UkoKoshka [18]

Answer:

  • DBMS , function - include concurrency, security, backup and recovery, integrity and data descriptions.
  • Software calculator , category - calculator
  • DTP , function - Creating, editing, saving and printing documents.
8 0
3 years ago
Angular where to set httpclient root url.
Trava [24]

Answer:

start with what you know

Explanation:

you can learn a lot more

8 0
2 years ago
Which one of these components is a part of the central processing unit (cpu)of a computer
katovenus [111]

Answer:

Control Unit

Explanation:

4 0
3 years ago
Other questions:
  • Prompt the user for a string that contains two strings separated by a comma. (1 pt)Examples of strings that can be accepted:Jill
    5·1 answer
  • ________ is typically used as the last string of letters in the name of a website. Group of answer choices the name of the indiv
    13·1 answer
  • Write the following function without using the C++ string class or any functions in the standard library, including strlen(). Yo
    12·1 answer
  • Which of the following types of access controls do not describe a lock? (a)- Directive (b)- Physical (c)- Preventative (d)- Dete
    8·1 answer
  • Studying MyMagic+ helps one understand the costs associated with information systems deployment at scale. According to your read
    12·1 answer
  • The user can set their own computer hostname and username. Which stage of the hardware lifecycle does this scenario belong to?
    6·1 answer
  • What is one way to improve the upward flow of information?
    12·1 answer
  • How many characters does the "short text" have?
    9·1 answer
  • TP1. लेखा अभिलेखको अर्थ उल्लेख गर्नुहोस् । (State the mea
    15·1 answer
  • Give three examples of NON-TRADITIONAL web authoring tools<br> 3 pour
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!