-2

Source code:

int main(void) {

    double values[10];
    int size = 5;
    double max_val = values[0];
    double min_val = values[0];

    printf("Enter 10 double values for the array\n");
    for (int i = 0; i < size; i++) {
        scanf("%lf", &values[i]);
    }

    for (int x = 0; x < size; x++) {
        if (values[x] > max_val) {
            max_val = values[x];
        }
        if (values[x] < min_val) {
            min_val = values[x];
        }
    }

    printf("Maximum value: %.2lf\n", max_val);
    printf("Miniimum value: %.2lf\n", min_val);
    return 0;

}

Enter 10 double values for the array

10.4
56.7
21.1
0.3
4.8


Maximum value: 56.70
Minimum value: -92559631349317830736831783200707727132248687965119994463780864.00
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278

1 Answers1

2
double max_val = values[0];
double min_val = values[0];

You have assigned junk values to max_val and min_val, as values[0] is not assigned any value at this point

You should move this assignment after you take input in the for loop

Pras
  • 4,047
  • 10
  • 20