ECS 30B

Homework #3

Winter 2009

 

Due:          Monday, Jan 26. 


All:  11:59pm using handin to cs30b, p3 directory.

Filenames: car.c, projectile.c, round.c  biggest.c

 


 

Programming: All programs should be able to compile with no warnings when compiled with the –Wall option. You should put your name(s) in a comment on the first line of each file.  The prompts and output format of each program must match the following examples exactly.  The actual values calculated by the programs may vary slightly from the examples.  To use functions from math.h, you must have –lm on your compile line (that is an “l” as in library) to link with the math library, e.g., gcc –Wall –lm car.c.

 

#1. (p. 140)  Filename: car.c. Use the math function  pow

 

[…@pc…]$ car.out

Please enter the principal, and interest> 10000 18

Please enter the number of payments> 36

Your loan of $10000.00 will have monthly payments of $361.52.

[…@pc…]$

 

#4 (p. 141)  Filename: projectile.c.

       Your code  must include a function named display_instructions which simply displays the instructions (first para below). Think: what are the arguments to this function? What is the return type? Writing it should be easy--it's just printing stuff.

 

[…@pc…]$ projectile.out

This program computes the duration of a projectile's flight,

and its height above the ground when it reaches the target.

The program will ask you for the angle of elevation (in radians),

the distance to the target (in feet), and the project velocity

(in feet per second).

 

Please enter the angle, distance, velocity> 0.3 11000 800

The projectile will take 14.393 seconds to reach the target.

The projectile will hit the target at a height of 70.6 feet.

[…@pc…]$

 

#5 ( p. 142)  Filename: round.c  (TRICKY!)

     This can be done without calling any functions.

 

[…@pc…]$ round.out

Please enter a positive number> 32.4851

That rounded is 32.4900

[…@pc…]$

 
Last:  Given 3 numbers, find the biggest. FUN problem---try to minimize the number of comparisons, and not repeat comparison.
       Hint: Use an extra variable to store partial results :-)


 
[…@pc…]$
./biggest.out
  Please enter 3 numbers separated by spaces > 30 10 70
  70 is the biggest