I think there is a faster way to do this - see my notes on your tidied code (please learn to use code tags)
Code:
#include<stdio.h>
int main() /* -- note that main() must always return int */
{
int num1,num2,num3,max,mid,min;
printf("Enter first number:");
scanf("%d",&num1);
printf("\n\nEnter second number:");
scanf("%d",&num2);
printf("\n\nEnter third number:");
scanf("%d",&num3);
if(num1>num2 && num1>num3)
{
max=num1;
if(num2>num3) /*-- note that if this is true the num1 > num3 check was redundant */
{
mid=num2; /* you could do away with these allocations steps and just printf() when you know the answer */
min=num3;
}
else
{
min=num2;
mid=num3;
}
}
else
{
if(num2>num1 && num2>num3) /* note that you already checked num1 > num2 */
{
max=num2;
if(num1>num3) /* -- if this is true then num2 > num3 check above is redundant */
{
mid=num1;
min=num3;
}
else
{
min=num1;
mid=num3;
}
}
else
{
max=num3;
if(num1>num2) /* -- this is the third time you've done this comparison! */
{
mid=num1;
min=num2;
}
else
{
min=num1;
mid=num2;
}
}
}
printf("\n\n%d\t%d\t%d\n\n", max,mid,min);
return 0; /* -- return 0 if successful */
}
anil_beloved - you also need to learn to use code tags. Also, this is a C board, not C++. Also your code is more compact and extendable but it is not necessarily the fewest execution steps (I don't think) because your code always makes 3 comparisons (and that's not counting looping overhead). You could get away with 2.67 comparisons on average.