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
Named constants should be used when they serve to improve readability and understanding. T or F
prisoha [69]
The answer is true.

Let's say we are calculating the volume of a grain silo where the the width is a constant, but the height can be changed.

In our code we would calculate the volume using something like:

PI * (WIDTH / 2)^2 * height

The variables in all caps would be named constants. Using them makes the code more readable to other people than if we were to just use their values like:

3.14 * (145.75 / 2)^2 * height




8 0
3 years ago
Read 2 more answers
A client sends seven equal sized segments with sequence numbers 15, 25, 35,45, 55, 65, and 75. Segments with sequence numbers 35
ikadub [295]

Answer: I believe the answer is 6

Explanation: taking 35 and 65 out leaves the rest of the numbers; 15,25,45,55, and 75.

3 0
3 years ago
How to create a function, called separate_int_and_str, which takes in a list and separates out the integer values and strings in
gregori [183]

Answer:

program :

def separate_int_and_str(list_1):# function to seprate the list.

   str_list=[] #list to hold the

   int_list=[]#list which holds the integer value.

   for x in list_1: #for loop to extract the list.

       if(type(x)==str): #if condition to check the type of the element.

           str_list.append(x)#create a list for the string value.

       elif(type(x)==int): #check condition for th einteger value.

           int_list.append(x)#create a list for the integer value.

Explanation:

  • The above-defined function is written in the python language, which used the code to separate the list for integer and the string value.
  • There are two lists define in the function which holds the integer and the string value separately.
  • There is a 'for' loop which scans the element of the list and checks the list by the help of type function which tells the class of the element.
  • Then if the type function states that the element is from the strong class, it will assign the element on the string list otherwise it assigns the element in the integer list.
4 0
3 years ago
Call your function from Example 1 three times with different kinds of arguments: a value, a variable, and an expression. Identif
Blizzard [7]

Answer:

Example 1:

def function(num):  

   print(num*2)

Example 2:

function(5)

num = 2

function(num)

function(3-1)

Explanation:

Given:

See attachment for complete question

To start with Example (1)

def function(num):  

   print(num*2)

<em>Note that; the above code segment which doubles the parameter, num could have been any other code</em>

<em />

<em>In Example (1), the parameter is num</em>

For example (2):

We can call the function using:

#1. A value:

function(5)

<em>In #1, the argument is 5; a value</em>

#2. A Variable

num = 2

function(num)

<em>In #2, the argument is num; a variable</em>

#3. An Expression

function(3-1)

<em>In #3, the argument is 3-1; an expression</em>

8 0
3 years ago
A typical pda includes a(n) _____.
Ratling [72]
A.External Monitor.Hope I helped.
5 0
3 years ago
Read 2 more answers
Other questions:
  • When you copy text, the selected text is copied from the original location and placed on the
    9·1 answer
  • When creating a query using the query design command, first you must ____?
    13·1 answer
  • In your own words, describe what Internet Protocols are. Why is it important to have agreed upon protocols?
    6·1 answer
  • The filter feature in excel allows you to look at what Data?
    7·1 answer
  • When including multiple images in a report, it may help to create a _____ on each image so you can cross reference them througho
    11·1 answer
  • In the event of a network attack or intrusion, a _____ lists the tasks that must be performed by the organization to restore dam
    5·1 answer
  • What output is generated by this for loop?
    6·1 answer
  • All who are interested in forex trading and bitcoin mining follow me for account management to all who are busy with work so i c
    14·1 answer
  • What is the best way to improve an online search?
    11·2 answers
  • There are many reasons to convert to the decimal numbering system. Select the best answer. When checking numeric values in compu
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!