12,764,163 members (39,956 online)
Rate this:
See more:
My 3rd qestion..:D
The request is: Input 4 numbers and print on screen:
1. Max and Min.
2. The remaning numbers.

I successfully coding the frist (Max and Min). The code's here:

```#include<stdio.h>

int main()
{
int a,b,c,d;
printf("Input a: ");
scanf("%i", &a);
printf("Input b: ");
scanf("%i", &b);
printf("Input c: ");
scanf("%i", &c);
printf("Input d: ");
scanf("%i", &d);
if(a>b&&a>c&&a>d) printf("Max is: %i\n", a);
if(b>a&&b>c&&b>d) printf("Max is: %i\n", b);
if(c>a&&c>b&&c>d) printf("Max is: %i\n", c);
if(d>a&&d>b&&d>c) printf("Max is: %i\n", d);
if(a<b&&a<c&&a<d) printf("Min is: %i\n", a);
if(b<a&&b<c&&b<d) printf("Min is: %i\n", b);
if(c<a&&c<b&&c<d) printf("Min is: %i\n", c);
if(d<a&&d<b&&d<c) printf("Min is: %i\n", d);
system("pause");
return 0;
}

```

Now i get stuck at the algorithm of the 2nd request...Can you give me a solution? (And of course, the code if you can). Thank you!!^^
Posted 12-Sep-12 18:23pm
prashant patil 4987 13-Sep-12 0:30am

hey Minh, are youwant to do this multiple times.?

Rate this:

## Solution 1

```/*
Create an integer Array. and store input data into that array. I assume that you know how to store input data into array.
*/```

```void main(void)
{
int arrMaxMin[4] = {23,43,45,12}; /* you have to store input values into array. I have hard coded value for an example. */
int arrsize = sizeof(arrMaxMin) / sizeof(int);
int max = max_array(arrMaxMin,arrsize );
int min = min_array(arrMaxMin,arrsize );

printf("The max is %d\n", max);
printf("The min is %d\n", min);

printf("\nArray:\n");
print_remainingarray(arrMaxMin, arrsize, max, min);

}

int max_array(int arrMaxMin[], int arrsize)
{
int i, max=arrMaxMin[0];
for (i=0; i<arrsize;>     if (arrMaxMin[i]>max)
max=arrMaxMin[i];
return(max);
}
int min_array(int arrMaxMin[], int arrsize)
{
int i, min=arrMaxMin[0];
for (i=0; i<arrsize;>	 if (arrMaxMin[i]<min)>
min=arrMaxMin[i];
return(min);
}

void print_remainingarray(int arrMaxMin[], int arrsize, int max, int min)
{
int i;
for(i=0; i<arrsize;>       if(arrMaxMin[i]!= max & arrMaxMin[i]!= min)
printf("%d ", arrMaxMin[i]);
}
printf("\n");
}

```

`/* Mark it as an answer if it helps you. */`
Minh Hikari 13-Sep-12 7:55am

is there any more simple way (only using if-else)???

Top Experts
Last 24hrsThis month
 OriginalGriff 295 Graeme_Grant 198 Karthik Bangalore 170 Peter Leow 145 CPallini 120
 OriginalGriff 4,962 Peter Leow 3,599 ppolymorphe 2,953 Karthik Bangalore 2,909 Graeme_Grant 2,744