1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <stdio.h>
int main(void)
{
int Array[5];
int TempArray[3];
int i;
int j;
int max1;
int max2;
int mid;
int min1;
int min2;
for (i = 0; i < 5; ++i){
printf("Please enter a number: ");
scanf("%d", &Array[i]);
}
max1 = Array[0];
min1 = Array[0];
// To find the maximum and minimum numbers in the whole list.
for (i=1; i<=4; ++i){
if (max1<Array[i])
max1 = Array[i];
if (min1>Array[i])
min1 = Array[i];
}
j=0;
// To find the sub-list of numbers from the main list.
for (i=0; i<=4; ++i){
if (max1 != Array[i]){
if (min1 != Array[i]){
TempArray[j] = Array[i];
++j;
}
}
}
max2 = TempArray[1];
min2 = TempArray[1];
// To find the maximum and minimum numbers in the sub-list.
for (j=0; j<=2; ++j){
if (max2<TempArray[j])
max2 = TempArray[j];
if (min2>TempArray[j])
min2 = TempArray[j];
}
// To find the middle number in the list.
for (j=0; j<=2; ++j){
if (TempArray[j] != max2)
if (TempArray[j] != min2)
mid = TempArray[j];
}
printf("In Ascending Order: %d, %d, %d, %d, %d\n", min1, min2, mid, max2, max1);
printf("In Descending Order: %d, %d, %d, %d, %d\n", max1, max2, mid, min2, min1);
system("PAUSE");
}
|