T or F? In an && operation, if the first operand is true the result is true.

False

T or F? In an && operation, if the first operand is false the result is false.

True

T or F? In an || operation, if the first operand is true the result is true.

True

T or F? In an && operation, if both operands are true the result is true.

True

T or F? In an || operation, if the first operand is false the result is false.

False

T or F? In the evaluation of a logical expression, ! has priority over the && and || operations.

True

T or F? In the evaluation of a logical expression, parentheses have higher priority than logical operators.

True

T or F? In the evaluation of a logical expression, arithmetic operators have higher priority than relational and logical operators.

True

T or F? In the evaluation of a relational expression, relational operators have lower priority than logical operators.

False

Given the following logical values, expr1 =t true, expr2 = false, expr3 = true, expr4 = false, evaluate the following logical expressions. expr1 && expr2 || expr3

True

Given the following logical values, expr1 =t true, expr2 = false, expr3 = true, expr4 = false, evaluate the following logical expressions. expr1 || expr2 && expr3

True

Given the following logical values, expr1 =t true, expr2 = false, expr3 = true, expr4 = false, evaluate the following logical expressions. !expr2 && expr1 || expr4

True

Given the following logical values, expr1 =t true, expr2 = false, expr3 = true, expr4 = false, evaluate the following logical expressions. !expr2 && (expr1 || expr3)

True

Given the following logical values, expr1 =t true, expr2 = false, expr3 = true, expr4 = false, evaluate the following logical expressions. !(expr1 && expr3) || expr1

True

Given the following values for the variables, a =10, b = 5, c = 12, and d = 8, evaluate the following relational and logical expressions. a > b || b < c && d > b

True

Given the following values for the variables, a =10, b = 5, c = 12, and d = 8, evaluate the following relational and logical expressions. !(a < b && c >d) || c < d

True

Given the following values for the variables, a =10, b = 5, c = 12, and d = 8, evaluate the following relational and logical expressions. a <= b || !b < c && d > a

False

Given the following values for the variables, a =10, b = 5, c = 12, and d = 8, evaluate the following relational and logical expressions. a > c && !d < c || (a > b && b

True

Given the following values for the variables, a = 10, b = 15, c = 10, and d = 25, evaluate the following relational expressions. a >= c

True

Given the following values for the variables, a = 10, b = 15, c = 10, and d = 25, evaluate the following relational expressions. b < d

True

Given the following values for the variables, a = 10, b = 15, c = 10, and d = 25, evaluate the following relational expressions. a * b / 2 >= c + d / 5 + 2

True

Given the following values for the variables, a = 10, b = 15, c = 10, and d = 25, evaluate the following relational expressions. a - b <= c + d - 4

True

Write code for the following selection structure flowchart.

if(c1)

{

if(c2)

stmt3;

else

stmt2;

}

else

stmt1;

T/F? A relational expression assigns values to the operands, which make it true.

False

T/F? When a relational operator has two characters such as >= or <= or != there should not be any spaces between them.

True

T/F? In a relational expression with arithmetic operations, arithmetic operations are performed before the relaitonal operations.

True

T/F? A relational expression may compare operands of any data type.

False

T/F? Relational expressions are used to make logical choices in branching control structures.

True

T/F? Relational expressions evaluate to 0 or 1.

True

T/F? Relational expressions are also called conditions.

True

var1(false) && var2(false)

False

var1(false) && var2(true)

False

var1(true) && var2(false)

False

var1(true) && var2(true)

True

var1(false) || var2(false)

False

var1(false) || var2(true)

True

var1(true) || var2(false)

True

var1(true) || var2(true)

True

Write the flowcharts and the code for the selection structure for the statement:

If x is greater than 25, add 20 to y.

if(x > 25)

y += 20;

Write the flowcharts and the code for the selection structure for the statement:

If z is less than 15, add x to y.

if(z < 15)

y += x;

Write the flowcharts and the code for the selection structure for the statement:

If n is 40, input values to l, m, and r.

if(n == 40)

scanf(" %d %d %d %d", &l, &m, &r)

Write the flowcharts and the code for the selection structure for the statement:

If p is greater than or equal to r, increment r by 1.

if(p >= r)

r++;

Write the segment of C code for the following:

If the compression stress is greater than 50,000, execute the following code.

printf("stress = %8d\n", stress);

printf("This stress si greater 50000\n");

if(stress > 50000)

{

printf("stress = %8d\n", stress);

}

Write the segment of C code for the following:

If the number of cars sold per month by XYZ Motor Company is greater than 10,000, add a 5% bonus to employees' monthly paychecks.

if(sales > 10000)

pay = pay + 0.05 * pay;

Write the segment of C code for the following:

If the monthly sales of an employee exceeds $50,000, award a 10% bonus, if it exceeds $100,000 award a 15% bonus, if it exceeds $150,000, award a 20% bonus. If it is less than $10,000 there will be no bonus.

if(sales > 150000)

pay = pay + 0.20 * pay;

else

{

if(sales > 100000)

pay = pay + .15 * pay;

else

{

if (sales > 50000)

pay = pay + .10 * pay;

}

}

T/F?

In a for loop the initialization, condition, and the increment are all in the header.

True

T/F?

A for loop can count by 10.

True

T/F?

In a for loop the index can be incremented or decremented.

True

T/F?

for loops can be nested one inside the other.

True

T/F?

When two for loops are nested, the loop variables myst be distinct.

True

T/F?

In a for loop stement, more than one variable can be initialized, by using a comma (,) operator.

True

What is the error?

for(i = 0; i < 10; i++);

should not be a semicolon at the end

What is the error?

for(i = 10; i < 0; i++)

loop will not execute as termination condition is false

What is the error?

for(i = 0; i < 10; i--)

loop will not terminate as termination condition is larger than initial value and index i is being decremented

What is the error?

for(i = 0; i < 10, i++)

"," where there should be a ","

What is the error?

for(i = 0; i < 10; i++)

for(i = 0; i < 10; i++)

nested inner and outer loops use the same index variable

What is the error?

for(i = 0; i < 10; i++)

for(j = 0; j < 8; j++)

for(i = 0; i < 5; i ++)

nested inner and outer loops use the same index variable

What is printed in the following simple for loops?

for(i = 0; i < 4; i++)

printf("Inside for loop i = %d\n", i);

printf("Outside for loop i = %d\n", i);

Inside for loop i = 0

Inside for loop i = 1

Inside for loop i = 2

Inside for loop i = 3

Outside for loop i = 4

What is printed in the following simple for loops?

for(i = 5; i > 0; i-)

printf("i = %d\n", i);

printf("Outside for loop i = %d\n", i);

i = 5

i = 4

i = 3

i = 2

i = 1

Outside for loop i = 0

What is printed in the following simple for loops?

for(i = 0, sum = 0; i < 4; i++)

{

sum += i;

printf("Inside loop i = %d\n", i);

}

printf("Outside loop i = %d\n", i);

printf("Sum = %d\n", sum);

Inside loop i = 0

Inside loop i = 1

Inside loop i = 2

Inside loop i = 3

Outside loop i = 4

Sum = 6