Frankie, here's your code with just a few lines commented out. Run it and see the answer.
#include <stdio.h>
#include <stdlib.h>
#define MIN(x,y) ( (x<y) ? (x) : (y) )
#define MAX(x,y) ( (x>y) ? (x) : (y) )
#define NELEMS 50
double vector[NELEMS];
int main(void)
{
double min1,min2,min3, max1,max2,max3, minx=0.0, maxx=0.0;
for(int i=0;i<NELEMS;i++)
// vector[i]=(double) (rand())/RAND_MAX*100;
vector[i] = (double) i * 3.55;
min1=min2=min3=vector[0];
max1=max2=max3=vector[0];
double x = 0.0;
for(int i=1;i<NELEMS;i++) {
x = vector[i];
// CASE 1: this code doesn´t work *********************
// min1=MIN(min1, x);
// max1=MAX(max1, x);
// Case 2: neither this *******************************
min2 = (min2 > x ? x : min2);
max2 = (max2 < x ? x : max2);
// Case 3: but this works *****************************
// if( min3 > x ) min3 = x;
// if( max3 < x ) max3 = x;
}
printf("\n\n");
// printf("Case 1 -> MIN =%8.4f MAX =%8.4f\n",min1,max1);
printf("Case 2 -> MIN =%8.4f MAX =%8.4f\n",min2,max2);
// printf("Case 3 -> MIN =%8.4f MAX =%8.4f\n",min3,max3);
printf("\n\n");
return EXIT_SUCCESS;
}
I get the same as I posted earlier.
John