UMBC CS 201, Spring 06
 UMBC CMSC 201 Spring '06 CSEE | 201 | 201 S'06 | lectures | news | help Search Notes:

 CMSC 201 Programming Project One Number Theory Out: Wednesday 2/22/06 Due Date: Wednesday 3/1/06, before midnight

## The Objective

The objective of this assignment is to get you familiar with good design practices, writing in C in a Unix environment, using functions, and using separate compilation. It may also heighten your appreciation of mathematics.

## The Background

The study of mathematics is separated into many fields. The one that tends to lead students to discover the beauty of mathematics is the field of number theory. This field deals with numbers and their relationships to each other.

The field of number theory has lead to discoveries such as :

• Prime numbers -- those which can only be divided by themselves and one. Some special primes that you might find interesting are of the form 2p - 1, where p is prime. These are called Mersenne Primes after the French monk Marin Mersenne who discovered them. The search for Mersenne primes continues. You can participate in the search for new Mersenne primes by joining GIMPS (the Great Internet Mersenne Prime Search). The 43rd and largest known Mersenne prime is 230402457 - 1. It was just discovered on December 15, 2005 by Dr. Curtis Cooper and Dr. Steven Boone from Central Missouri State University.

• Perfect numbers -- ancient mathematicians were interested in the relationship of a number and the sum of its divisors. A positive integer that is equal to the sum of its divisors (excluding itself) is called a "perfect" number. For example, the divisors of 6 are 1, 2 and 3. Since 6 = 1 + 2 + 3, 6 is a perfect number. The next three perfect numbers are 28, 496 and 8128. If the sum of the divisors is greater than the number, the number is called "abundant". If the sum of the divisors is less than the number, the number is called "deficient". Perfect numbers demonstrate some interesting properties -- all known perfect numbers end in 6 or 8; there are no known odd perfect numbers. Mersenne primes and perfect numbers are closely related.

• Squares -- many positive integers are considered geometric in nature. You learned about perfect squares in high school -- 1, 4, 9, 16. They are called "squares" because a group of 1, 4, 9 or 16 dots can be arranged in a square. • Cubes -- similarly, perfect cubes are positive integers that are geometric in nature. The numbers 1, 8, 27, 64, and 125 are called "cubes" because a group of 1, 8, 27, 64 or 125 dots can be arranged in a cube. This image, courtesy of Eric W. Weisstein, "Cubic Number", from MathWorld--A Wolfram Web Resource shows the cubes formed by 8 dots and 27 dots. • Triangular numbers -- Groups of 1, 3, or 6 dots can be arranged in a triangle and so these numbers are called "triangular" numbers. (If you've ever gone bowling, you'll recognize that 10 is also triangular.)
A more natural example arises when we consider a group of people who meet for the first time and everyone shakes hands with everyone else. The number of handshakes will be a triangular number.
Turns out that triangular numbers are the sum of consecutive integers. 1 = 1 3 = 1 + 2 6 = 1 + 2 + 3 10 = 1 + 2 + 3 + 4 To us this may just be an interesting relationship. To early Pythagoreans, it showed the mysterious nature of the universe and the way in which numbers and shapes have esoteric relationships.

Positive integers can be categorized in many different ways. This project will let you investigate some familiar and some new ways of looking at integers.

Your mission is to write a program that examines positive integers within a range that the user specifies and categorizes them as follows:

1. ODD or EVEN
2. PRIME or COMPOSITE -- a prime number is an integer greater than one that is divisible only by itself and one. Any number that is not "prime" is "composite".
3. PERFECT / ABUNDANT / DEFICIENT --- as described above
4. SQUARE -- as described above
5. CUBE -- as described above
6. TRIANGULAR -- as described above
Your program will also count the number of integers in the specified range that fall into each category and print a summary at the end. You should restrict the user to positive integers between 1 and 100000, inclusive. The ending number specified by the user should always be greater than or equal to the starting number s/he chose. You must validate the user's input. I guarantee that all input used to test your program will be of type int.

Your program MUST include the following functions. Do NOT change the function prototypes given below. You may choose to use more functions if you wish, but these are sufficient. All "predicate" functions below should return 1 for TRUE and 0 for FALSE. You have some flexibility in implementing the other functions. Choose wisely (and use #defines)

• void PrintGreeting (void); -- displays a suitable greeting to the user
• int GetValidInt (int min, int max); -- gets an integer from the user between min and max, inclusive and returns that valid integer.
• int IsOdd (int n); -- a predicate function that returns TRUE if n is Odd and returns FALSE if it is not.
• int IsPrime (int n); -- a prediate funtion that returns TRUE if n is prime, and FALSE if it is not
• int CheckForPerfect (int n); -- classifies n as "perfect", "abundant" or "deficient". A different value is returned for each different category.
• int SumDivisors (int n); -- returns the sum of the divisors of n.
• int IsDivisor (int a, int b); -- a predicate function that returns TRUE if a is a divisor of b, and FALSE if not
• int IsSquare (int n); -- returns TRUE if n is a perfect square, FALSE if not
• int IsCube (int n); -- returns TRUE if n is a perfect cube, FALSE if not
• int IsTriangular (int n); -- returns TRUE if n is a triangular number, FALSE if not
• void PrintTableLine (int n, int odd, int prime, int perfect, int square, int cube, int triangular);
-- prints the information for one number on one line of the table
• void PrintTotals (int first, int last, int numOdd, int numEven, int numPrime,
int numComposite, int numDeficient, int numPerfect, int numAbundant,
int numSquare, int numCube, int numTriangular);

-- prints the summary of the number of different classifications found in the range specified.

You MUST use separate compilation for this project.

Since you will have to use a function from the C math library, you will not only need to #include <math.h> but you must also link using the -lm option. Here is how you'll need to compile your files :
gcc -c -Wall -ansi proj1.c
gcc -c -Wall -ansi numbers.c
gcc proj1.o numbers.o -lm

## Sample Run

Although your output need not be identical to the above, all information (including the greeting) must be present.

## Submitting the Program

You must name your source file that contains main() proj1.c The file that contains the functions relating to numbers should be called numbers.c and the header file should be called numbers.h. To submit your project, type the following at the Unix prompt:

submit cs201 Proj1 proj1.c numbers.c numbers.h

To verify that your project was submitted, you can execute the following command at the Unix prompt. It will show all files that you submitted in a format similar to the Unix 'ls' command.

submitls cs201 Proj1

CSEE | 201 | 201 S'06 | lectures | news | help

Wednesday, 22-Feb-2006 08:07:28 EST

`