Homework 2: Bases & Programs
Due: Tuesday 9/20 by 1pm
Objectives
- Practice converting numbers between bases.
- Writing and submitting your first C programs.
The Assignment
Note: Question 1 & 2 should be completed on paper and turned in physically.- Convert the following decimal (base 10) numbers into octal
(base 8) and hexadecimal (base 16):
53
You may use a calculator, but you must how all of your work.
124
255 - Convert the following hexadecimal (base 16) numbers into
octal (base 8) and decimal (base 10):
F9
You may use a calculator, but you must how all of your work.
147
3AF72 - Write a C program that prints out the following poem with
the restriction that your program can have at most 3
printf statements. (Note: the output from your
program must have the same punctuation and indentation shown
below.)
There was a man from Nantucket Who kept all his cash in a bucket But his daughter, named Nan, Ran away with a man And as for the bucket, Nantucket.
submit cs104_chang hw02 hw2-3.c
- We saw in class that the %d placeholder can be
used in printf statements to print out integer values.
You can also use %x to print out integer
values in hexadecimal and %o to print out integer values
in octal. Play around with %x and %o in your
program. Now write a program that gives you the answers to
question #1 of this assignment.
Name your program hw2-4.c and submit your program using
submit cs104_chang hw02 hw2-4.c
Use the script Unix command to record yourself compiling and running this program. (Remember to 'exit' after you are done.) Then, submit the typescript file:
submit cs104_chang hw02 typescript
- (Extra Credit)
Write a C program that gives you the answers to question #2 of this
homework assignment. Look up "hexadecimal constant". Name your
program hw2-5.c
and submit it using:
submit cs104_chang hw02 hw2-5.c
Be sure to logout completely when you have finished!