| < Day Day Up > |
|
if statements: Write a program that declares two integer variables, a and b, initialized to values of your choice. In this program write ten if statements that use the following conditions:
(a <= b) |
!(b == a) |
(3 < a) && (3 < b) |
(a || b) |
(((++a) == (--b)) || b) |
(a ^ b) |
((a && b && (!0)) || true) |
(b == 10) |
(int c = b) |
(a || (!b)) |
Disassemble your source code and examine how each if statement and its condition is implemented in assembly.
if-else statement: Write a program that declares two char variables, a and b, and initialize them both to ‘ ‘. Write ten if-else statements using the following condition expressions:
(a = ‘y’) |
(a == ‘Y’) |
(!(b = ‘n’)) |
(b == ‘n’) |
(‘c’ <= b) |
((‘A’ <= a) && (a <= ‘Z’)) |
(a == b) |
(a != b) |
((b >= a) || (a <= ‘1’)) |
(a && b && ‘0’) |
nested if-else statements: Write a program using nested if-else statements that reads character input from the keyboard one character at a time and performs the following operations:
if the input is ‘1’ through ‘5’, add 1 to the character value and print the resulting character to the screen,
if the input is ‘6’ through ‘9’, add 5 to the character value and print the resulting character to the screen,
if the input is ‘a’ through ‘z’, convert to upper case and print to the screen,
if the input is ‘A’ through ‘Z’, convert to lower case and print to the screen.
switch statement: Rewrite exercise three above using a switch statement.
while statement: Add a while statement to the code you wrote in exercise four to repeatedly process keyboard input. Use a sentinel value to terminate the loop.
do-while statement: Use do-while statements to calculate the following: Prompt the user for the value of n.
for statement: Rewrite exercise 6 using for statements.
| < Day Day Up > |
|