assignment1

The third describes the character 7 whose value is

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: nsisting of the character ’7’. The third describes the character ’7’, whose value is its ASCII character code (55). (c) Consider the statement double ans = 10.0+2.0/3.0−2.0∗2.0; Rewrite this statement, inserting parentheses to ensure that ans = 11.0 upon evaluation of this statement. Answer: double ans = 10.0+2.0/((3.0−2.0)∗2.0); Problem 1.2 Consider the statement double ans = 18.0/squared(2+1); For each of the four versions of the function macro squared() below, write the corresponding value of ans. 1. #define squared(x) x*x Answer: 18.0/2 + 1 ∗ 2 + 1 = 9 + 2 + 1 = 12. 2. #define squared(x) (x*x) Answer: 18.0/(2 + 1 ∗ 2 + 1) = 18/5 = 3.6. 1 3. #define squared(x) (x)*(x) Answer: 18.0/(2 + 1) ∗ (2 + 1) = 6 ∗ 3 = 18. 4. #define squared(x) ((x)*(x)) Answer: 18.0/((2 + 1) ∗ (2 + 1)) = 18/9 = 2. Problem 1.3 Write the “Hello, 6.087 students” program described in lecture (slides 22 and 27) in your favorite text editor and compile and execute it. Turn in a printout or screen shot showing • the command used to compile your program • the command used to execute your program (using gdb) • the output o...
View Full Document

Ask a homework question - tutors are online