hw4_solution

hw4_solution - EME5 Homework 4 Solutions October 22, 2010 4...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
EME5 Homework 4 Solutions October 22, 2010 4 Chapter 5, Problem 13 sum = 4 5 Chapter 5, Problem 14 5.1 Part b 5.1.1 Solution Code #include <stdio.h> #include <math.h> int main() { double x, x0, xf, xstep, result; int i, n; printf(" x f2(x)\n"); printf(" ---------------\n"); x0 = -1.0; /* initial value for x */ xf = 5.0; /* final value for x */ xstep = 0.25; /* step size for x */ n = (xf - x0)/xstep + 1; /* number of points */ for(i = 0; i < n; i++) { x = x0 + i*xstep; /* calculate value x */ result = x*x*sqrt(2*x); printf("%8.4f %8.4f\n", x, result); } return 0; } 5.1.2 Solution Output x f2(x) --------------- 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
-1.0000 nan -0.7500 nan -0.5000 nan -0.2500 nan 0.0000 0.0000 0.2500 0.0442 0.5000 0.2500 0.7500 0.6889 1.0000 1.4142 1.2500 2.4705 1.5000 3.8971 1.7500 5.7294 2.0000 8.0000 2.2500 10.7392 2.5000 13.9754 2.7500 17.7356 3.0000 22.0454 3.2500 26.9292 3.5000 32.4105 3.7500 38.5117 4.0000 45.2548 4.2500 52.6608 4.5000 60.7500 4.7500 69.5423 5.0000 79.0569 6 Chapter 5, Problem 21 6.1 Solution Pseudocode declare p, y, r, n read p, r for (n = 1 to 30 with step 1) y = p (1+r)n print y endfor 2
Background image of page 2
6.2 Solution Flowchart 6.3 Solution Code #include <stdio.h> #include <math.h> int main() { double y, p, r; int n; printf("Enter the principal: "); scanf("%lf", &p); printf("Enter the interest rate (%%): "); scanf("%lf", &r); printf("year total\n"); for(n = 1; n <= 30; n++) { y = p*pow((1+r/100), n); printf("%d $%.2f\n", n, y); } return 0; } 6.4 Solution Output Enter the principal: 10000 Enter the interest rate (%): 8 year total 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
1 $10800.00 2 $11664.00 3 $12597.12 4 $13604.89 5 $14693.28 6 $15868.74 7 $17138.24 8 $18509.30 9 $19990.05 10 $21589.25 11 $23316.39 12 $25181.70 13 $27196.24 14 $29371.94 15 $31721.69 16 $34259.43 17 $37000.18 18 $39960.19 19 $43157.01 20 $46609.57 21 $50338.34 22 $54365.40 23 $58714.64 24 $63411.81 25 $68484.75 26 $73963.53 27 $79880.61 28 $86271.06 29 $93172.75 30 $100626.57 4
Background image of page 4
Chapter 5, Problem 28 7.1 Solution Flowchart 7.2 Solution Code #include <stdio.h> int main() { int i, j; printf(" 10 9 8 7 6 5 4 3 2 1\n"); printf(" -------------------------------------------\n"); for(i=10; i>=1; i--) { /* outer loop */ printf("%4d|", i); for(j=10; j>=i; j--) { /* inner loop */
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/23/2011 for the course EME 5 taught by Professor Staff during the Fall '08 term at UC Davis.

Page1 / 18

hw4_solution - EME5 Homework 4 Solutions October 22, 2010 4...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online