C coding: Please complete the following code, do not change the main function- n
ID: 3802156 • Letter: C
Question
C coding:
Please complete the following code, do not change the main function- nothing below "void run_test(double x, double y, double z, char * label);" can be changed:
#include <stdio.h>
// (a) Begin the definition a function called get_min that returns the
// minimum of its three double precision floating point
// arguments.
// The arguments may be called anything, you like, but something simple
// like x, y, and z will suffice.
// (c) Implement the logic required to calculate the minimum
// of the three input values, and return the result.
// (b) End the definition of get_min.
void run_test(double x, double y, double z, char * label);
int main(void) {
run_test(2, 2, 2, "All items equal");
run_test(2, 3, 4, "Ascending");
run_test(6, 5, 4, "Descending");
run_test(1, 1, 3, "Two in a row, then ascending");
run_test(5, 5, 2, "Two in a row, then descending");
run_test(2, 6, 6, "Two in a row, then ascending");
run_test(6, 3, 3, "Two in a row, then descending");
run_test(2, 1, 4, "Minimum in the middle");
run_test(2, 5, 4, "Maximum in the middle");
return 0;
}
void run_test(double x, double y, double z, char * label) {
printf(" Running test: %s Data = %0.17f, %0.17f, %0.17f ", label, x, y, z);
double extreme = get_min(x, y, z);
printf("The extreme value is %0.17f ", extreme);
}
Explanation / Answer
#include <stdio.h>
// (a) Begin the definition a function called get_min that returns the
// minimum of its three double precision floating point
// arguments.
// The arguments may be called anything, you like, but something simple
// like x, y, and z will suffice.
// (c) Implement the logic required to calculate the minimum
// of the three input values, and return the result.
// (b) End the definition of get_min.
double get_min(double x, double y, double zl);
void run_test(double x, double y, double z, char * label);
int main(void) {
run_test(2, 2, 2, "All items equal");
run_test(2, 3, 4, "Ascending");
run_test(6, 5, 4, "Descending");
run_test(1, 1, 3, "Two in a row, then ascending");
run_test(5, 5, 2, "Two in a row, then descending");
run_test(2, 6, 6, "Two in a row, then ascending");
run_test(6, 3, 3, "Two in a row, then descending");
run_test(2, 1, 4, "Minimum in the middle");
run_test(2, 5, 4, "Maximum in the middle");
return 0;
}
void run_test(double x, double y, double z, char * label) {
printf(" Running test: %s Data = %0.17f, %0.17f, %0.17f ", label, x, y, z);
double extreme = get_min(x, y, z);
printf("The extreme value is %0.17f ", extreme);
}
double get_min(double x, double y, double z){
double min = x;
if(min>y){
min=y;
if(min>z)
min=z;
}
else if(min > z)
min = z;
return min;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.