[英]C program to display largest and smallest number from 3 number which is taken input from user
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. 我有3个数字A,B,C ,如果要保持状态不变,我需要在相同的值中找到最小值和最大值。
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. 在单个if语句中需要这样的内容。 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 . 所以-如果A大,那么B或C是最小的,那么您的条件就可以了,否则C \\ B是最大的,而smallet是第二个和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 我没有检查代码是否可以编译,但是我认为它可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.