Anda di halaman 1dari 8

Have the user enter in a temperature in Fahrenheit a. Convert the temperature to Celsius C=(F-32)/1.8 b.

. Display a statement that explains the conversion c. If the Celsius temperature is less than 0 tell the user it is freezing, if it is greater than 100 tell them it is boiling. Have the user enter in a temperature in Celsius d. Convert the temperature to Fahrenheit F=(9/5)*C+32 e. Display a statement that explains the conversion f. If the Fahrenheit temperature is less than 32 tell the user it is freezing, if it is greater than 212 tell them it is boiling.

Math Program Part 1


1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. Create 2 random numbers based off of the minimum and maximum number supplied by the user. Display an addition problem to the user using the two numbers Have the user enter in their guess Using an ifelse statement tell them if they got it correct or incorrect and give other feedback Display a subtraction problem to the user using the two numbers Have the user enter in their guess Using an ifelse statement tell them if they got it correct or incorrect and give other feedback Display an multiplication problem to the user using the two numbers Have the user enter in their guess Using an ifelse statement tell them if they got it correct or incorrect and give other feedback Display a subtraction problem to the user using the two numbers Display an modulus (%) problem to the user using the two numbers Have the user enter in their guess Using an ifelse statement tell them if they got it correct or incorrect and give other feedback Display a subtraction problem to the user using the two numbers

Answer in Next pages

Complete the following expressions and equations. If a number does not have a decimal in it consider it to be an integer and do integer division. If it has a decimal in it consider it a float and do float division.

Expression 3 + 4 4 - 3 7 + 2 2 * (3 * 4) (2 * 3) * 4 7 < 5 7<5 && 5<7 7<5 || 5<7 T || T T || F

Value Produced

Expression 5 == 5 F && T !F 2 / 4 10 % 4 22 % 4 2 % 4 5 * 4 / 10 5 * (4 / 10) 5 * 4.0 / 10

Value Produced

7
1 9 24 24 False true False True False

True
True True 0.5 2 2 2 2 2 2.0

Decision Making and the Selection Structure Directions: Read all instructions carefully.

___

1) Which operator is used to test for equality


A. B. C. == D. =

True or False 2. The condition (3>4 || 12>9) is true T F

3. The condition (3>4 && 12>9 is true 4. The condition (3<4 && 7>4) is true

T T

F F

4) The following expressions make sense but are invalid according to C rules of syntax. Rewrite them so that they are valid logical expressions. (all variables are integer) x< y <= z

x, y, and z are greater than 0

x has the same value as y or z

Matching 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ && || ! < <= >= == > != = A. B. C. D. E. F. G. H. I. J. OR Not Equal to Not Less than or equal to Less than greater than or equal to Greater Than Equal To Assign And

15) Trace the output for the following code fragment (6) Program Output

int x = 5;

Part 1
printf(Part 1\n); if (x > 3) printf(A\n); if (x <= 10) printf(B\n);

A B Part 2 D

printf(Part 2\n); if (x > 5) printf(C\n); else printf(D\n);

16) What is the output of the following code fragment (4 pts)

int x = 4;

Program Output

Two
if (x > 10) printf(One\n); else printf(Two\n);

Three

if (x > 0) printf(Three\n); else printf(Four\n);

17)Draw the flowchart for this fragment. (8)

x = 9; if (y > 5) printf(First); else printf(Second); printf(%d, x);

Start

Initialize x=9, y=5

If(x>5)

Second

Print first

Print 9

End

18)Draw the flowchart for this fragment. (8)

int x = 32; int y = 7; if(x>y*5) { printf(%i is greater than %i\n,x,y*5);

}else {printf(%i is less than %i\n,x,y*5); }


Start

Initialize x=32, y=7

If(x>y*7)

Less then

Greater then

End

Anda mungkin juga menyukai