im trying to write a source code that find the smallest, largest and average of numbers in array. the code runs fine, but it is not giving the highest number and the the average should include only four number excluding highest and smallest number from the array.
This looks wrong: for(int j = 0; j < 6 + 1; j++)
On the next line numbers[j] will be accessing numbers[6] which is the non-existent seventh element of the array.
(Actually it isn't necessary to sort the array if all you need is the highest, lowest and total, you can get those values in a single pass through the array - or indeed get rid of the array and capture them during the user input process).
int smallest=0;
int largest=0;
// find the largest and smallest element
for(int i = 0; i < 6 ; i++){
if(numbers[i] < smallest)
{
smallest=numbers[i];
}
if(numbers[i]>largest)
{
largest=numbers[i];
}
}
// average
for(int i = 0; i < 6 ; i++){
sum=sum+numbers[i];
}
average=(sum-largest-smallest)/4;