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

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

View Full Document Right Arrow Icon
(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
Image of page 2

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

View Full Document Right Arrow Icon
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
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern