UMBC CMSC 201 Spring '09 UMBC | CSEE | 201 | 201 S'09 | lectures | projects | help |
CMSC 201 Number Theory Out: Wednesday 2/18/09 |
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 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 :
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:
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. void PrintTableHeading (void); -- prints the heading of the table int IsOdd (int n); -- a predicate function that returns TRUE if n is Odd and returns FALSE if not. int IsPrime (int n); -- a prediate funtion that returns TRUE if n is prime, and FALSE if 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 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 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 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 -c -Wall -ansi util.c
gcc proj1.o numbers.o util.o -lm
Although your output need not be identical to the above, all information (including the greeting) must be present.
You must name your source file that contains main() and the other
functions that are specific to this project proj1.c.
The file that contains the functions relating to number theory should be
called numbers.c and its header file should be called numbers.h.
The file that contains utility functions, i.e. GetValidInt(), that you are
likely to reuse in other projects, should be called util.c and its
header file should be called util.h.
To submit your project, type the following at the Unix prompt:
submit cs201 Proj1 proj1.c numbers.c numbers.h util.c util.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
Thursday, 19-Feb-2009 08:25:52 EST