I need to solve this problem:
I have 3 nubmers A,B,C and i need to find the minimum and the maximum in the same if statemeant.
I writed the code below and it didn't works, i need to solve that problem in this format could anyone help me?
#include <stdio.h>
int main()
{
int a,b,c;
printf("\nEnter Three numbers = ");
scanf("%d%d%d",&a ,&b, &c);
if( (a > b) && (a > c) )
{
if(b > c)
{
printf("a is largest\n");
printf("c is smallest\n");
}
else
{
printf("a is largest\n");
printf("b is smallest\n");
}
}
else
{
if(c > a)
{
printf("c is largest\n");
printf("b is smallest\n");
}
else
{
printf("a is largest\n");
printf("c is smallest\n");
}
}
return 0;
}
Need it kind of like this in single if statement. Please help me out
A | B | C
----------
2 | 1 | 0
2 | 0 | 1
1 | 2 | 0
1 | 0 | 2
0 | 1 | 2
0 | 2 | 1
SO- if A is the big so B or C is the smallest so your condition is OK else C\\B is the biggest and the smallet is the small between the second and A .
if((a>b)&&(a>c){
if(b>c){ printf("A biggest , C smallest);
}else{ printf("A biggest , B smallest);
}else{
if(b>c){
if(a>c){ printf("B biggest , C smallest);
}else{ printf("B biggest , A smallest);
}else{
if(a>b){ printf("C biggest , B smallest);
}else{ printf("C biggest , A smallest);
}
}
}
I hope that will help you. i didn't check if the code compile but i think its work
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.