Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i find the middle number

Status
Not open for further replies.

greyone

Programmer
Dec 14, 2000
200
CA
hi i have a function to calculate the max and the min of three numbers as follows. But i want to use these two functions to find out the middle number. Please help.



#include <stdio.h>
int minof3(int a, int b, int c);
int maxof3(int a, int b, int c);
main()
{
int a,b,c,middle_value;

printf(&quot;Enter the first number=> &quot;);
scanf(&quot;%d&quot;, &a);

printf(&quot;Enter the second number=> &quot;);
scanf(&quot;%d&quot;, &b);

printf(&quot;Enter the third number=> &quot;);
scanf(&quot;%d&quot;, &c);
printf(&quot;\n&quot;);
maxof3(a,b,c);
minof3(a,b,c);


// middle_value=a+b+c-maxof3(a,b,c)-minof3(a,b,c);
//printf(&quot;The middle value is %d \n&quot;,middle_value);
printf(&quot;\n&quot;); printf(&quot;\n&quot;);
}
int maxof3(int a, int b, int c)
{
if (a>b && a>c) printf(&quot;%d is the highest number \n\n&quot;,a);
else if (b>c && b>a) printf(&quot;%d is the highest number \n\n&quot;,b);
else if (c>a && c>b) printf(&quot;%d is the highest number \n\n&quot;,c);
}

int minof3(int a, int b, int c)
{
if (a<b && a<c) printf(&quot;%d is the lowest number \n\n&quot;,a);
else if (b<c && b<a) printf(&quot;%d is the lowest number \n\n&quot;,b);
else if (c<a && c,b) printf(&quot;%d is the lowest number \n\n&quot;,c);
printf(&quot;\n&quot;);
}



 
...
int array[3];

for (int q = 0;q < 3;q ++)
{
printf(&quot;Please enter %d value: &quot;,(q+1));
scanf(&quot;%d&quot;,array[q]);
}

printf(&quot;\n&quot;);

for (q = 0;q <2;q ++)
for (int w = 0;w < 2;w ++)
{
static int temp;
if (array[w]>array[w+1)
{
temp = array[w];
array[w] = array[w+1];
array[w+1] = temp;
}
}

int max,mid,min;
max = array[2];
mid = array[1];
min = array[0];
...


Best Regards,

aphrodita@mail.krovatka.ru {uiuc rules}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top