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
svet-max [94.6K]
3 years ago
5

Provide trace tables for these loops. a. int i = 0; int j = 10; int n = 0; while (i < j) { i++; j--; n++; } b. int i = 0; int

j = 0; int n = 0; while (i < 10) { i++; n = n + i + j; j++; } c. int i = 10; int j = 0; int n = 0; while (i > 0) { i--; j++; n = n + i - j; } d. int i = 0; int j = 10; int n = 0; while (i != j) { i = i + 2; j = j - 2; n++; }
Computers and Technology
1 answer:
Eduardwww [97]3 years ago
3 0

Answer:

Following  show the trace table.

Explanation:

a)

int i = 0; int j = 10; int n = 0;

while (i < j) { i++; j--; n++;

}

i                  j             n

1                  9           1

2                 8           2                                              

3                 7            3

4                 6            4  

5                5             5                                                

b)                  

int i = 0; int j = 0; int n = 0;

while (i < 10) { i++; n = n + i + j; j++;

}

i                j             n          

1               1             2

2              2            4

3              3            9      

4              4            16

5              5            25

6              6           36

7               7           49

8               8           64

9               9           81

10             10          100

c)

int i = 10; int j = 0; int n = 0;

while (i > 0) { i--; j++; n = n + i - j; }

i              j           n

9            1           8

8           2           14  

7            3           18

6            4          20

5            5           18

4            6           14

3           7            8

2           8            0

1            9           -10

d)

int i = 0; int j = 10; int n = 0; while (i != j) { i = i + 2; j = j - 2; n++; }

i                 j                n

2                8               1

4                6               2

6                4               3

8                2               4

10              0                5

12             -2                6

14             -4                 7

...               ...                ...

...               ...               ...    

...              ...                ...

You might be interested in
What is your favorite anime?
ira [324]

Answer:

Fullmetal Alchemist: Brotherhood (160,975)

Explanation:

Fullmetal Alchemist: Brotherhood (160,975)

6 0
2 years ago
Kristen wants to view the records of her database in ascending order. What should she do?
Elanso [62]

the answer is Sort the table

6 0
3 years ago
Read 2 more answers
Microsoft Word Module 3 the answers for online class University MIS
Artist 52 [7]

Answer:

Nope

Explanation:

You can use open office for free

7 0
3 years ago
HELLO. A computer can only understand the numbers 1 and 2.<br><br> TRUE OR FALSE
dimulka [17.4K]

FALSE

I know they can understand 0's

3 0
2 years ago
Write a Python program that can compare the unit (perlb) cost of sugar sold in packages with different weights and prices. The p
Virty [35]

Answer:

<em>This program is written using python</em>

<em>It uses less comments (See explanation section for more explanation)</em>

<em>Also, see attachments for proper view of the source code</em>

<em>Program starts here</em>

<em></em>

#Prompt user for price of package 1

price1 = int(input("Enter Price 1: "))

while(price1 <= 0):

     price1 = int(input("Enter Price 1: "))

#Prompt user for weight of package 1

weight1 = int(input("Enter Weight 1: "))

while(weight1 <= 0):

     weight1 = int(input("Enter Weight 1: "))

#Calculate Unit of Package 1

unit1 = float(price1/weight1)

print("Unit cost of Package 1: "+str(unit1))

#Prompt user for price of package 2

price2 = int(input("Enter Price 2: "))

while(price2 <= 0):

     price2 = int(input("Enter Price 2: "))

#Prompt user for weight of package 2

weight2 = int(input("Enter Weight 2: "))

while(weight2 <= 0):

     weight2 = int(input("Enter Weight 2: "))

#Calculate Unit of Package 2

unit2 = float(price2/weight2)

print("Unit cost of Package 2: "+str(unit2))

#Compare units

if unit1 > unit2:

     print("Package 1 has a better price")

elif unit1 == unit2:

     print("Both Packages have the same price")

else:

     print("Package 2 has a better price")

<em></em>

Explanation:

price1 = int(input("Enter Price 1: ")) -> This line prompts the user for price of package 1

The following while statement is executed until user inputs a value greater than 1 for price

while(price1 <= 0):

     price1 = int(input("Enter Price 1: "))

weight1 = int(input("Enter Weight 1: ")) -> This line prompts the user for weight of package 1

The following while statement is executed until user inputs a value greater than 1 for weight

while(weight1 <= 0):

     weight1 = int(input("Enter Weight 1: "))

unit1 = float(price1/weight1) -> This line calculates the unit cost (per weight) of package 1

print("Unit cost of Package 1: "+str(unit1)) -> The unit cost of package 1 is printed using this print statement

price2 = int(input("Enter Price 2: ")) -> This line prompts the user for price of package 2

The following while statement is executed until user inputs a value greater than 1 for price

while(price2 <= 0):

     price2 = int(input("Enter Price 2: "))

weight2 = int(input("Enter Weight 2: ")) -> This line prompts the user for weight of package 2

The following while statement is executed until user inputs a value greater than 1 for weight

while(weight2 <= 0):

     weight2 = int(input("Enter Weight 2: "))

unit2 = float(price2/weight) -> This line calculates the unit cost (per weight) of package 2

print("Unit cost of Package 2: "+str(unit2)) -> The unit cost of package 2 is printed using this print statement

The following if statements compares and prints which package has a better unit cost

  • <em>If unit cost of package 1 is greater than that of package 2, then package 1 has a better price</em>
  • <em>If unit cost of both packages are equal then they both have the same price</em>
  • <em>If unit cost of package 2 is greater than that of package 1, then package 2 has a better price</em>

if unit1 > unit2:

     print("Package 1 has a better price")

elif unit1 == unit2:

     print("Both Packages have the same price")

else:

     print("Package 2 has a better price")

4 0
3 years ago
Other questions:
  • Exposing employee and customer personal data to an untrusted environment is an example of:
    9·1 answer
  • A private network that is accessible only to employees of the company that created it is called:
    11·1 answer
  • The list below represents the contents of a computer's main memory. I've left every other byte blank. Assume that the letters at
    14·1 answer
  • Which of the following terms describes a type of useful and legitimate software that is distributed by a developer where they do
    10·1 answer
  • Why do some people put salt on sidewalks when it snows?
    14·1 answer
  • How fast is light? person that answers this will get points ​
    12·1 answer
  • What property do we use to distinguish a specific element from a form? value name click this
    12·1 answer
  • Using filtering as a strategy to deal with information overload requires Group of answer choices reviewing all unsolicited infor
    14·1 answer
  • King(a. has eaten b.ate c.had eaten) when Airah called​
    8·1 answer
  • The classes Person and Airplane shall have the property to print information about themselves on a printer. Draw class and inter
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!