Due: Monday, July 1st, 2024 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.
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).
As usual, 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
valgrind
)cpplint --clint
.
You should submit your exercise to the course Gradescope.