1 / 12

Homework Assignment #4

Homework Assignment #4. J. H. Wang Dec. 3, 2007. Homework Assignment #4. Chap. 5 Exercise 5.4: 4, Prog. 1 (p.230) Exercise 5.7: Prog. 2 (p.250) Exercise 5.8: Prog. 1 (p.254) Quick-Check Exercises: 7 (p. 270) Programming Projects: 2 (p. 273) Chap. 6 Exercise 6.2: 2, Prog.1 (p.295)

Download Presentation

Homework Assignment #4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Homework Assignment #4 J. H. Wang Dec. 3, 2007

  2. Homework Assignment #4 • Chap. 5 • Exercise 5.4: 4, Prog. 1 (p.230) • Exercise 5.7: Prog. 2 (p.250) • Exercise 5.8: Prog. 1 (p.254) • Quick-Check Exercises: 7 (p. 270) • Programming Projects: 2 (p. 273) • Chap. 6 • Exercise 6.2: 2, Prog.1 (p.295) • Exercise 6.4: 2 (p.302) • Programming Projects: 5 (p.325) • Deadline: • Three weeks (Due: Dec. 24, 2007)

  3. Details • Exercise 5.4: (p.230) • 4. What values are assigned to n, m, and p, given the initial values i=3 and j=9? n = ++i *--j;m = i + j--;p = i + j; • Prog. 1. Write a loop that displays a table of angle measures along with their sine and cosine values. Assume that the initial and final angel measures (in degrees) are available in init_degree and final_degree (type int variables), and that the change in angle measure between table entries is given by step_degree (also a type int variable). Remember that the math library’s sin and cos functions take arguments that are in radians.

  4. Exercise 5.7: (p.250) • Prog. 2. Write nests of loops that cause the following output to be displayed:00 10 1 20 1 2 30 1 2 3 40 1 2 30 1 20 10

  5. Exercise 5.8: (p.254) • Prog. 1. Design an interactive input loop that scans pairs of integers until it reaches a pair in which the first integer evenly divides the second.

  6. Quick-Check Exercises: (p. 270) • 7. During execution of the following program segment:a. How many times does the first call to printf execute?b. How many times does the second call to printf execute?c. what is the last value displayed?for (i=0; i<7; ++i){ for (j=0; j<i; ++j) printf(“%4d”, i*j); printf(“\n”);}

  7. Programming Projects: 2 (p. 273) • a. Write a program that will find the smallest, largest, and average values in a collection of N numbers. Get the value of N before scanning each value in the collection of N numbers. • b. Modify your program to compute and display both the range of values in the data collection and the standard deviation of the data collection. To compute the standard deviation, accumulate the sum of squares of the data values (sum_squares) in the main loop. After loop exits, use the formula:

  8. Exercise 6.2: 2, Prog.1 (p.295) • 2. Show the table of values for x, y, and z that is the output displayed by the following program. You will notice that the function sum does not follow the suggestion in the last Program Style segment of Section 6.2. You can improve this program in the programming exercise that follows. (on the next page) • Prog. 1. Rewrite the function in Self-Check Exercise 2 as a function that takes just two input arguments. The sum computed should be returned as the function’s type int result. Also, write an equivalent function main that calls your sum function.

  9. #include <stdio.h>void sum(int a, int b, int *cp);int main(void){ int x, y, z; x=5; y=3; printf(“ x y z\n\n”); sum(x, y, &z); printf(“%4d%4d%4d\n”, x, y, z); sum(y, x, &z); printf(“%4d%4d%4d\n”, x, y, z); sum(z, y, &x); printf(“%4d%4d%4d\n”, x, y, z); sum(z, z, &x); printf(“%4d%4d%4d\n”, x, y, z); sum(y, y, &y); printf(“%4d%4d%4d\n”, x, y, z); return 0;}

  10. Exercise 6.4: 2 (p.302) • 2. a. Classify each formal parameter of double_trouble and trouble as input, output, or input/output. • b. What values of x and y are displayed by this program? (Hint: Sketch the data areas of main, trouble, and double_trouble as the program executes.) • (The program is on the next page.)

  11. void double_troube(int *p, int y);void trouble(int *x, int *y);int main(void){ int x, y; trouble(&x, &y); printf(“x=%d,y=%d\n”, x, y); return 0;}void double_trouble(int *p, int y){ int x; x = 14; *p = 2*x-y;}void trouble(int *x, int *y){ double_trouble(x, 5); double_trouble(y, *x);}

  12. Programming Projects: (p.325) • 5. Determine the following information about each value in a list of positive integers.a. Is the value a multiple of 7, 11, or 13?b. Is the sum of the digits odd or even?c. Is the value a prime number?You should write a function with three type int output parameters that send back the answers to these three questions. Some sample input data might be:104 3773 13 121 77 30751

More Related