Beruflich Dokumente
Kultur Dokumente
Homework 2
Due Monday August 5, 2002
There are ten problems. You have two weeks to complete as many as you
can. They range from very simple to challenging, increasing (roughly)
with difficulty from 1 to 10. Do each problem in a separate file,
named according to our conventions: p2_1.c, p2_2.c, ... p2_10.c. None
of these should require any techniques that we haven't studied in the
first two weeks. However, you are welcome to read ahead and use
anything that we haven't studied if you feel it makes the program
easier. I will be adding hints/tips/techniques throughout the course
of the two weeks. Please consult the course web page.
1. Write a program which computes the modulus of two ints entered
at the command line.
ex.
prompt > mod 6 4
The answer is: 2
(program ends)
3. Write a program that finds and prints the largest integer given
an arbitrary number of inputs (using argc/argv).
prompt > max 1 2 3 1 2 5 1 2
5
(program ends)
references: see ex1.c, add_n_numbers.c
6. Write a program that runs continuously and allows the user to add
subtract, multiply, divide, and take the modulus of two integers, or
take the factorial of a single number. The program must parse
standard operators for these operations:
ex.
prompt > ./adding_machine
$ 3 + 2
5
$ 3!
6
$ 3 % 2
1
$ edaf
input error
$ end
(program ends)
additional details:
* Your program should allow zero or more white spaces. So,
3+ 2, 3 + 2, 3!, 3 !, etc., should all work as well.
* You only need to handle one operation at a time. So, I DO NOT
expect you to parse, 3! + 2!, 3 + 2/2, etc.
7. Write a program which returns only the unique values of an input
list of integers.
prompt > uniq 1 2 -1 1 3 3
1 2 -1 3
(program ends)
8. Write a program that computes the number of days between any two
dates (inclusive). You must take into account leap years. The rule
for computing a leap year is as follows:
If the year is divisible by 4 it is a Leap Year ...
Unless the year is divisible by 100, then it is _not_ a Leap Year ...
Unless the year is divisible by 400, then it _is_ a Leap Year.
During a Leap year, an extra day is added at the end of the month
of Feb.