Tho gram supposed to produce Min and Max values of entered numbers. It gives Max but it always shows 0 as minimum value. Does anyone know what happened?
Code:
//largeSmall.c
#include <stdio.h>
int max, min;
int compare(int num1, int num2, int num3, int num4);
int main(void) {
int i, ent1, ent2, ent3, ent4;
FILE *csci;
for (i = 1; i <= 4; ++i) {
csci = fopen("csci.txt", "w");
printf("Enter four numbers: ");
scanf("%d %d %d %d", &ent1, &ent2, &ent3, &ent4);
compare(ent1, ent3, ent2, ent4);
printf("The biggest number: %d. The smallest number is: %d \n", max, min);
}
fclose(csci);
}
int compare(int num1, int num2, int num3, int num4) {
if (num1 > num2 && num1 > num3 && num1 > num4) {
max = num1;
return max;
}
else if (num2 > num1 && num2 > num3 && num2 > num4) {
max = num2;
return max;
}
else if (num3 > num1 && num3 > num2 && num3 > num4) {
max = num3;
return max;
}
else if (num4 > num1 && num4 > num2 && num4 > num3) {
max = num4;
return max;
}
else if (num1 < num2 && num1 < num3 && num1 < num4) {
min = num1;
return min;
}
else if (num2 < num3 && num2 < num1 && num2 < num4) {
min = num2;
return min;
}
else if (num3 < num2 && num3 < num1 && num3 < num4) {
min = num3;
return min;
}
else if (num4 < num2 && num4 < num3 && num1 < num1) {
min = num4;
return min;
}
}