TO FIND MAXIMUM & MINIMUM OF THREE NUMBERS


#include<stdio.h>
void main()
{
int a,b,c;
printf("Enter 3 numbers");
scanf("%d%d%d",&a,&b,&c);
if(a>b && a>c)
printf("Mximum number is a = %d",a);
else if(b>a && b>c)
printf("Mximum number is b = %d",b);
else
  printf("Mximum number is c = %d",c);
if(a<b && a<c)
printf("Minimum number is a = %d",a);
else if(b<a && b<c)
printf("Minimum number is b = %d",b);
else
  printf("Minimum number is c = %d",c);
}



15 comments: (+add yours?)

Unknown said...

thanks bro..

Readsm said...

Finally I got the solution but I also need a pseudo code of this problem.

Anonymous said...

What if I enter all three as same number.

Siraj Shaikh said...

I have not check yet..i think it will show you garbage value.

Unknown said...

Great bro

Chandan Maurya said...

Noop, it's working ✌

Avi said...

wrong code .If a=b then it always return c,means max and min
value will be same in that case.which is wrong

Admin said...

Nice Post. You cal also do this using command line arguments. Source code is here https://www.computerscienceai.com/2018/02/c-program-to-accept-three-integers-as.html

Anonymous said...

Great! It works! Thanks!

Unknown said...

Show output

Unknown said...

Show output

Hitesh said...

// If you dont want to reverse operator ..you can do like this solution :

#include
using namespace std;
void check(int a,int b, int c){

if((a>=b && a>=c)){
if(b=a && b>=c)){
if(a>a>>b>>c;
check(a,b,c);
return 0;
}

Noodles said...

#include
int main()
{
int a1,a2,a3,max,min;
printf("enter value of a1, a2, a3\n");
scanf("%d%d%d",&a1,&a2,&a3);

if(a1a3)
{
max= a2;
}
else
{
max = a3;
}
}
else
{
min =a3;
max = a2;
}

}
else if(a2a3)
{
max =a1;
}
else
max = a3;
}
else
{ min =a3;
if(a2>a1)
{
max = a2;
}
else
max = a1;
}
printf(" maximum = %d\n",max);
printf(" minimum = %d\n",min);
return(0);
}

Unknown said...

Show output plz

Anonymous said...

Try this

#include
int main()
{
int a, b, c,max,min;
printf("Enter three numbers\n");
scanf("%d%d%d", &a, &b, &c);

max= (a>b)&&(a>c)?a : (b>a)&&(b>c)?b : c;
printf("The maximum number: %d\n", max);

min = (a<b)&&(a<c)?a : (b<a)&&(b<c)?b : c;
printf("The minimum number: %d\n", min);
return 0;
}

Post a Comment