Click here to Skip to main content
12,764,163 members (39,956 online)
Rate this:
Please Sign up or sign in to vote.
See more: C
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:


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);
    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.?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

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);

   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)
int min_array(int arrMaxMin[], int arrsize)
   int i, min=arrMaxMin[0]; 
   for (i=0; i<arrsize;>	 if (arrMaxMin[i]<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]);

/* 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)???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170217.1 | Last Updated 13 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100