2.11 Integer division and modulo

Ace your homework & exams now with Quizwiz!

Determine the result. Some expressions only use literals to focus attention on the operator, but most practical expressions include variables. (5 + 10 + 15) * (1 / 3)

0

Determine the result. Some expressions only use literals to focus attention on the operator, but most practical expressions include variables. 4 / 9

0

Determine the result. Type "Error" if appropriate. Only literals appear in these expressions to focus attention on the operators; most practical expressions include variables. 50 % 2

0

Determine the result. Type "Error" if the program would terminate due to divide-by-zero. Only literals appear in these expressions to focus attention on the operators; most practical expressions include variables. 100 * (1 / 2)

0

Determine the result. Type "Error" if appropriate. Only literals appear in these expressions to focus attention on the operators; most practical expressions include variables. 51 % 2

1

Type the program's output. #include <iostream> using namespace std; int main() { int x; int y; x = 1; y = 2 * (x + 8); cout << x << " " << y; return 0; }

1 18

Type the program's output. #include <iostream> using namespace std; int main() { int x; int y; x = 13; y = x % 4; cout << x << " " << y; return 0; }

13 1

Determine the result. Some expressions only use literals to focus attention on the operator, but most practical expressions include variables. x / y where int x = 10 and int y = 4.

2

Type the program's output. #include <iostream> using namespace std; int main() { int x; int y; x = 2; y = (3 * (x + 2)) + 4; cout << x << " " << y; return 0; }

2 16

Type the program's output. #include <iostream> using namespace std; int main() { int a; int x; int y; a = 2; x = 2; y = a * x; y = y + 5; cout << x << " " << y; return 0; }

2 9

Determine the result. Some expressions only use literals to focus attention on the operator, but most practical expressions include variables. 10 / 4.0

2.5

Determine the result. Some expressions only use literals to focus attention on the operator, but most practical expressions include variables. x / y where x = 10 and double y = 4.0.

2.5

Determine the result. Some expressions only use literals to focus attention on the operator, but most practical expressions include variables. 13 / 3

4

Type the program's output. #include <iostream> using namespace std; int main() { int x; int y; x = 5; y = x % 3; cout << x << " " << y; return 0; }

5 2

Type the program's output. #include <iostream> using namespace std; int main() { int x; int y; x = 5; y = x / 2; cout << x << " " << y; return 0; }

5 2

Determine the result. Type "Error" if the program would terminate due to divide-by-zero. Only literals appear in these expressions to focus attention on the operators; most practical expressions include variables. 100 * 1 / 2

50

Determine the result. Type "Error" if the program would terminate due to divide-by-zero. Only literals appear in these expressions to focus attention on the operators; most practical expressions include variables. 100 / 2

50

Determine the result. Type "Error" if appropriate. Only literals appear in these expressions to focus attention on the operators; most practical expressions include variables. 596 % 10

6

Type the program's output. #include <iostream> using namespace std; int main() { int x; int y; x = 7; y = x % 3; cout << x << " " << y; return 0; }

7 1

Determine the result. Type "Error" if appropriate. Only literals appear in these expressions to focus attention on the operators; most practical expressions include variables. 78 % 10

8

Determine the result. Type "Error" if appropriate. Only literals appear in these expressions to focus attention on the operators; most practical expressions include variables. 100 % (1 / 2)

Error

Determine the result. Type "Error" if the program would terminate due to divide-by-zero. Only literals appear in these expressions to focus attention on the operators; most practical expressions include variables. 100 / (1 / 2)

Error

Determine the result. Type "Error" if the program would terminate due to divide-by-zero. Only literals appear in these expressions to focus attention on the operators; most practical expressions include variables. x = 2; y = 5; z = 1 / (y - x - 3);

Error

Given a 16-digit credit card number stored in x, which gets the last (rightmost) four digits? (Assume the fourth digit from the right is non-zero). a. x / 10000 b. x % 10000

b

Given a non-negative random number x, which yields a random number in the range -10 to 10? a. x % -10 b. (x % 21) -10 c. (x % 20) -10

b

Which get the tens digit of x. Ex: If x = 693, which yields 9? a. x % 10 b. x % 100 c. (x / 10) % 10

c

Given a non-negative random number x, which yields a random number in the range 5 - 10? a. x % 5 b. x & 10 c. x % 11 d. (x % 6) + 5

d

Determine the result. Type "Error" if appropriate. Only literals appear in these expressions to focus attention on the operators; most practical expressions include variables. 100.0 % 40

Error

A cashier distributes change using the maximum number of five dollar bills, followed by one dollar bills. For example, 19 yields 3 fives and 4 ones. Write a single statement that assigns the number of 1 dollars bills to variable numOnes, given amountToChange. Hint: Use the % operator. #include <iostream> using namespace std; int main() { int amountToChange; int numFives; int numOnes; amountToChange = 19; numFives = amountToChange / 5; Put the answer here. cout << "numFives: " << numFives << endl; cout << "numOnes: " << numOnes << endl; return 0; }

numOnes = amountToChange / 5;


Related study sets

Globalization and Financialization

View Set

Chapter 15 Intracellular Compartments and Transport

View Set

Abeka 7th Grade History Appendix Quiz W

View Set

Prep U: Chpt. 39 Management of Patients with Nonmalignant Hematologic Disorders

View Set

Exercise 35- Lymphatic System and Immune Response

View Set

High renaissance in Northern Europe and Spain

View Set

Principles I - Real estate license

View Set