out: Wednesday, April 9, 2025
due: Friday, April 11, 2025 by 10:00 am,
No late exercises accepted.
Goals: Write a multi-file C program that properly uses header, implementation, and client files to partition a program.
Description: Your job is to write a multi-file C program. You should write the following three files:
NthPrime.h
: a header file, containing a single function
prototype declaration for a function called NthPrime()
, as well as comments
above the prototype documenting how to use the function. The
function should accept a single int16_t
parameter, and it
should return an int64_t
. The function should return the nth
prime number, where n
is the function's parameter. The function call
NthPrime(1)
should return 2, NthPrime(2)
should return 3,
NthPrime(3)
should return 5, and so on.
The result of NthPrime(n)
is not defined if n
<= 0, and
implementations do not need to check for this possibility.
NthPrime.c
: a file containing the implementation of
NthPrime
. Feel free to use the simplest possible primality
testing algorithm (hint: "x is not prime if it is divisible by ...").
You may also want to define some helper functions here as well.
ex4.c
: a file containing a main()
function that tests
NthPrime
by printing the input and output output of NthPrime
for at least two different, non-trivial arguments (but you do not need to
print an enormous number of test cases - keep it reasonable).
Your code must:
Do not submit a Makefile.bash$ gcc -Wall -g -std=c17 -c -o NthPrime.o NthPrime.c bash$ gcc -Wall -g -std=c17 -c -o ex4.o ex4.c bash$ gcc -Wall -g -std=c17 -o ex4 ex4.o NthPrime.o
cpplint --clint
.)
Since we haven't talked about to header guards or static functions in class yet,
you should ignore any warnings about these for this exercise (only),
and you do not need to include them.
You should submit your exercise using the Gradescope dropbox linked on the course resources web page.