# Thread: Find Min and Max of an array

1. ## Find Min and Max of an array

Hi. I have assignment to find difference between Min and Max of an array of 5 numbers. I did some work, but after compiling - my program does not run, it just stops working.. Can you help me, where is my mistake ? Array values needs to be double.

Code:
```#include <stdio.h>
#include <stdlib.h>

int main()
{
int i;            // element in array
int size;            // size of array
double array [i];    // number of elements in array
double min;          //minimum value
double max;          // maximum value
double difference;   // difference between maximum and minimum values

printf("Enter the size of the array: ");
scanf("%d",&size);
printf("Enter %d elements in to the array: ", size);
scanf("%d",&array[i]);

max = array[0];  // let first number in array be maximum
for (i=0; i<size; i++)
if (max < array [i])
max = array [i];
{
printf("Maximum value is: %d\n",max);
}

min = array [0]; // let first number in array be minimum
for (i=0; i<size; i++)
if (min>array[i])
min = array [i];
{
printf("Minimum value is: %d\n",min);
}

difference = max - min;

printf ("Difference between Min and Max values is %d\n", difference);

/*   if (i>= 5)
{
printf ("Only 5 numbers allowed. \n");
break;
}
*/

system("PAUSE");
return 0;
}```

2. what is happening here ..?? you got to loop size times with scanf if you want user to fill the array
printf("Enter %d elements in to the array: ", size);scanf("%d",&array[i]);
edit : on line 8 u declared array to random size as variable i is not initialized

3. You're using "%d" in your "scanf()" and "printf()" functions that are expecting doubles.
And on line 16, you're using 'i' uninitialized.

These corrections won't make your program correct, but it should let you compile and start troubleshooting.