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
Draw a dfd that shows how data will be stored, processed, and transformed in the tims system
Mkey [24]
First, the variable has to be declared. The type of the variable has to be declared as well. Next is the process of inputting data. After which, the variable is equated to the inputted data. A process using the variable comes afterward. Lastly, the variable is equated to the resulting value.
8 0
3 years ago
Powerful IT security systems are needed to defend against what appears to be authorized access to a network or application. Sele
FrozenT [24]

Answer:false

Explanation: why would you need a powerful it security system, if they already have authorized access?

6 0
3 years ago
A parameter is a numerical measure that describes a characteristic of a sample. Choose One • 4 points True False
garri49 [273]

the answer is false mufka

3 0
3 years ago
Ashley has many interests. She likes to read, listen to music, and play soccer with her friends. But her favorite thing to do is
attashe74 [19]

ashley has a lot of interests

7 0
3 years ago
A small company with 100 computers has hired you to install a local area network. All of the users perform functions like email,
charle [14.2K]

Answer:

Answer to the following question is as follows;

Explanation:

Windows 7 for 100 users and Windows 8.1 for 25 users are the best options since they both enable networking and active directory, and Windows 8.1 also offers Windows server capabilities.

Winxp would therefore work for $100, but it is unsupported and has no updates.

If you wish to go with open source, you can choose Ubuntu 16 or 18 or Linux.

8 0
3 years ago
Other questions:
  • What does subscribing to a website’s RSS feed provide to a subscriber?
    10·1 answer
  • What is the difference between primary storage,secondary storage and offline storage what type of storage can be
    6·2 answers
  • How to get the absolute value in coding begginners?
    13·2 answers
  • Digital printing is not suitable for printing what
    11·1 answer
  • A byte contains how many bits? Question 3 options:
    13·2 answers
  • According to the stage-gate process developed by Robert G. Cooper, _____ are the results of the previous stage and are the input
    15·1 answer
  • Describe a cellular network, its principle<br> components and how it works.
    7·1 answer
  • Discuss five domains of Instructional technology​
    7·1 answer
  • Why does it keep saying this when I’m putting my right credit card number
    6·1 answer
  • What is the binary conversion of 179.187.223.21?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!