CS113: Homework 1

Turn in a PRINTOUT of your program (no sample data necessary) with your full name and netID, in class or in my mailbox (657 Rhodes) by 5 p.m. AND e-mail the source code (and only the source code) to wes28@cs.cornell.edu.

Please create a separate .c file for each problem. The names for the .c files are given along with the problem description. You may send all of the .c files as attachments to one email, or send each one separately. Please make "Assignment 1" the subject line of your email.

DO NOT just e-mail me your source code. YOU MUST turn in a printout of the code to receive credit for the assignment.

Problem: Counting Coins (coins.c)

Write a program that accepts a dollar amount (in cents) and computes the number of quarters, nickels, dimes and pennies needed. Your solution must use the fewest number of coins that are possible for the given dollar amount.

You may assume that the input is an integer amount greater than 0.

Here are some sample interactions with my program; your program should give identical output.

Enter a dollar amount (in cents): 50
You need:
* 2 quarters

Enter a dollar amount (in cents): 96
You need:
* 3 quarters
* 2 dimes
* 1 penny

Problem: Printing graph paper (graph.c)

Write a program that creates graph paper with user-specified dimensions. Your program should query the user for four positive integers: the height and width of the paper in terms of the number of squares, and the height and width of each square. You may assume that the height and width of each square is greater than 1, and that the height and width of the number of boxes is greater than 0. The graph paper should be output using the "+", "-", and "|" characters, as in the examples below. (Note: If you can't find or don't have these three characters on your keyboard, you may substitute any others - but you must use three distinct characters.) Here are some sample interactions with my program; your program should give identical output.

Enter height (number of boxes): 3
Enter width (number of boxes): 4
Enter height of a box: 2
Enter width of a box: 3
+--+--+--+--+
|  |  |  |  |
+--+--+--+--+
|  |  |  |  |
+--+--+--+--+
|  |  |  |  |
+--+--+--+--+


Enter height (number of boxes): 1
Enter width (number of boxes): 2
Enter height of a box: 3
Enter width of a box: 3
+--+--+
|  |  |
|  |  |
+--+--+


Enter height (number of boxes): 2
Enter width (number of boxes): 1
Enter height of a box: 3
Enter width of a box: 6
+-----+
|     |
|     |
+-----+
|     |
|     |
+-----+


Enter height (number of boxes): 2
Enter width (number of boxes): 4
Enter height of a box: 3
Enter width of a box: 6
+-----+-----+-----+-----+
|     |     |     |     |
|     |     |     |     |
+-----+-----+-----+-----+
|     |     |     |     |
|     |     |     |     |
+-----+-----+-----+-----+

Problem: Divisor Sums (divisor.c)

We say that a positive integer d is a proper divisor of a positive integer n if n yields a remainder of 0 when divided by d, and d < n.

For example, the proper divisors of 12 are 1, 2, 3, 4, and 6. Therefore, the sum of the proper divisors of 12 is 1 + 2 + 3 + 4 + 6 = 16.

Write a program which accepts as input an integer m (which may be assumed to be 2 or greater) and prints out its proper divisors in ascending order, and the sum of its proper divisors.

A perfect number is one equal to the sum of its proper divisors. Can you find any? In addition to listing proper divisors, have your program report whether the input number is perfect or not:

Here are some sample interactions with my program; your program should give identical output.

Enter a number: 12
The sum of the proper divisor(s) of 12 is
1 + 2 + 3 + 4 + 6 = 16.
12 is not perfect.

Enter a number: 16
The sum of the proper divisor(s) of 16 is
1 + 2 + 4 + 8 = 15.
16 is not perfect.

Enter a number: 17
The sum of the proper divisor(s) of 17 is
1 = 1.
17 is not perfect.
If you can find any odd perfect numbers, let me know. I'll give you more extra credit than you know what to do with.