

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The objectives, hand-in requirements, and details of lab 6 in cs 2073 at utsa. Students are required to write and call c functions, define and use c preprocessor files, and implement functions for quadratic equations, factorials, divisors, and prime numbers. Prototypes and comments for each function.
Typology: Lab Reports
1 / 2
This page cannot be seen from the preview
Don't miss anything!


All laboratories will be submitted electronically through WebCT. Zip up your entire project folder to submit as the source. (Right click on the laboratory folder and follow the SentTo link.)
In this assignment, you will be writing some C functions, using C include headers, and call them. Design a C file, “utility.c”, that contains the following functions. The prototypes in the file are as follows.
/* The function quadratic calculates the solutions of the quadratic equation based on the formula:
ax^2 + bx + c = 0
x1 = −b −
b^2 − 4 ac 2 a
x2 =
−b +
b^2 − 4 ac 2 a It return 0 if no real number solutions, 1 if one (repeated) solution, or 2 if two solutions are found. The solutions are stored in x1 and x2 using call-by-reference technique. x1 will store the solution if 1 is returned. Both x1 and x2 store solutions if 2 is returned. Otherwise, x1 and x are invalid. The following table lists some test cases: a b c x1 x2 return value
1 -2 1 1 1 1 1 1 1 x x 0 1 -3 2 1 2 2
Note x in the table means don’t care. */ int quadratic(int a, int b, int c, double *x1, double *x2)
/* returns the factorial of number. The function fact(5) should return 120. (1 * 2 * 3 * 4 * 5 = 120) */ double fact(int number)
/* Outputs all of the divisors for number including 1 and the number The function print_all_divisor(24) outputs 1 2 3 4 6 8 12 24
void print_all_divisor(int number)
/* returns 1 if the number is prime and 0 otherwise. A number is prime if is has no divisors except itself and 1. The smallest possible prime number is 2. The function is_prime(5) returns 1. The function is_prime(12) returns 0. */ int is_prime(int number)
/* returns the sum of all of the divisors except the number itself The function sum_of_proper_divisor(24) returns 36. 1 + 2 + 3 + 4 + 6 + 8 + 12 = 36 */ int sum_of_proper_divisor(int number)
/* returns 1 if the number is perfect and 0 otherwise. A perfect number is a number such that the sum of its proper divisors equals the number The function is_perfect(6) returns 1 because 1 + 2 + 3 = 6 The function is_perfect(10) returns 0 because 1 + 2 + 5 != 10 */ int is_perfect(int number)
Edit a header file, “utility.h”, that contains all the above function prototypes. Add a line in your main.c file that includes the header. In your main.c file, code test programs to validate the examples listed in the above comments. You need to create a menu similar to the one designed in Lab 4 and Lab 5. Of course, you need to take the user’s inputs accordingly.
Compile and run your program until there are no errors. You may test your program at least once on each statement.