Question: Makefile -------- If a part asks for a program, you must provide a Makefile. The TAs will make no attempt to compile your program other
Makefile --------
If a part asks for a program, you must provide a Makefile. The TAs will make no attempt to compile your program other than typing "make".
The sample Makefile in the lecture notes is a good starting point for the Makefile you need to write for this lab. If you understand everything about the sample Makefile, you should have no problem writing this lab's Makefile.
Here are some additional documentations on Make:
- Stanford CS Education Library has a nice short tutorial on Makefiles. See Unix Programming Tools, Section 2, available at http://cslibrary.stanford.edu/107/.
- The manual for make is available at http://www.gnu.org/software/make/manual/make.html. Reading the first couple of chapters should be sufficient for basic understanding.
There are a few rules that we will follow when writing makefiles in this class:
- Always provide a "clean" target to remove the intermediate and executable files.
- Compile with gcc rather than cc.
- Use "-Wall" option for all compilations. - Use "-g" option for compiling and linking.
The sample Makefile follows all these rules.
Write a C program that reads 2 positive integers (of type int) from the user using scanf() function, prints the following information, and then terminates:
- the average of the two (this should be printed as a floating point number.)
- whether each number is a prime number or not
- whether the two numbers are relatively prime or not (see http://en.wikipedia.org/wiki/Coprime if you don't know what this means.)
You can assume that the user will input only positive integers, i.e., don't do any error checking.
In order to see if two numbers are relatively prime, you should calculate the GCD using Euclidean algorithm. You are allowed to look up the algorithm and/or code on the Internet, in which case you should cite the source in your README.txt file.
Your code should be organized as follows:
- gcd.h & gcd.c: GCD calculation function header and definition
- prime.h & prime.c: prime number testing function header and definition
- main.c: everything else
- Makefile
All files must be named EXACTLY as above, case-sensitive. When you run "make", it should build an executable file called "main".
The makefile should have correct dependencies. For example, if you build everything, change prime.h, and run make again, only prime.c and main.c should recompile, not gcd.c. (You can simulate changing a file by using 'touch' command.)
You can use
printf("You typed in %d and %d ", x, y);
to print integers, and
printf("The average is: %f ", avg);
to print a floating point number. And you should use
scanf("%d", &x);
to read an integer that the user types in. Don't forget the ampersand in front of the variable.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
