week7exercises (1).pdf

# A int n 1 int k 2 int r n if k n r k b int n 1 int k

• 3
• 100% (1) 1 out of 1 people found this document helpful

This preview shows pages 2–3. Sign up to view the full content.

(a) int n = 1; int k = 2; int r = n; if ( k < n ) { r = k; } (b) int n = 1; int k = 2; int r; if ( n < k ) { r = k; } else { r = k + n; } (c) int n = 1; int k = 2; int r = k; if ( r < k ) { n = r; } else { k = n; } (d) int n = 1; int k = 2; int r = 3; if ( r < n + k ) { r = 2 * n; } else { k = 2 * r; } R3.5 Suppose x and y are variables of type double. Write a code fragment that sets y to x if x is positive and to zero otherwise. R3.7 Explain why it is more difficult to compare floating-point numbers than integers. Write Java code to test whether an integer n equals 10 and whether a floating-point number x is approximately equal to 10. 2 of 3 n = 1 k = 2 r = 2 n = 1 k = 2 r = 3 n = 1 k = 1 r = 2 n = 1 r = 3 k = 6

This preview has intentionally blurred sections. Sign up to view the full version.

Chapter 3 Exercises CS 1121 Introduction to Programming R3.14 Draw a flowchart for the following algorithm: When two points in time are compared, each given as hours (in military time, ranging from 0 and 23) and minutes, the following pseudocode determines which comes first. If hour1 < hour2 time1 comes first. Else if hour1 and hour2 are the same If minute1 < minute2 time1 comes first. Else if minute1 and minute2 are the same time1 and time2 are the same. Else time2 comes first. Else time2 comes first. 3 of 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern