问下以下函数的具体意思及如何使用void foo2A(void) // Using a function to allow compiler to test the code{double varToTest = 9.1; // Give the variable to test a value to keep compiler happydouble maxDbl = DBLMIN; // Initialise max variable to system minimum (smallest +ve v
2019-05-03
问下以下函数的具体意思及如何使用
void foo2A(void) // Using a function to allow compiler to test the code
{
double varToTest = 9.1; // Give the variable to test a value to keep compiler happy
double maxDbl = DBL_MIN; // Initialise max variable to system minimum (smallest +ve value)
double minDbl = DBL_MAX; // Initialise min variable to system maximum (largest +ve value)
if (maxDbl < varToTest) {
maxDbl = varToTest;
}
else if (minDbl > varToTest) {
minDbl = varToTest;
}
}
// Similar type of comparision as foo1 for floating points
void foo2B(void) // Using a function to allow compiler to test the code
{
double varToTest = 9.1; // Give the variable to test a value to keep compiler happy
double maxDbl = -DBL_MAX; // Initialise max variable to -ve of system max (largest -ve value)
double minDbl = DBL_MAX; // Initialise min variable to system maximum (largest +ve value)
if (maxDbl < varToTest) {
maxDbl = varToTest;
}
else if (minDbl > varToTest) {
minDbl = varToTest;
}
}
详细说下怎么使用,比如说我有一个double型的数组,怎么引用这个函数得到数组中的最大最小值
优质解答
只是实现一个交换的功能,最大值与最小值.
只是实现一个交换的功能,最大值与最小值.