ECS 30A |
Homework #5 |
Fall 2008 |
Due: Wednesday, November 5.
Written:
4:00pm in 2131 Kemper.
Programs: 11:59pm using handin to cs30a p4 directory.
Filenames: square_root.c, calculator.c
Written: #1,
#2, #3, #4 on page 319.
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 examples exactly. 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 gcd.c
#7. page 326. Filename: square_root.c
[…@pc…]$square_root.out
The square root of 4 is approximately 2.0000
The square root of 120.5 is approximately 10.9772
The square root of 88 is approximately 9.3808
The square root of 36.01 is approximately 6.0008
The square root of 10000 is approximately 100.0000
The square root of 0.25 is approximately 0.5000
[…@pc…]$
#10, page 327.
Filename: calculator.c
[…@pc…]$ calculator.out
Repeatedly enter operator and operand (q 0 to end)
+ 5.0
result so far is 5.00
^ 2
result so far is 25.00
/ 2.0
result so far is 12.50
q 0
final result is 12.50
[…@pc…]$ calculator.out
Repeatedly enter operator and operand (q 0 to end)
+ 2.0
result so far is 2.00
* 3.0
result so far is 6.00
# 2
Invalid operation: #
Final result is 6.00
[…@pc…]$