简体   繁体   English

C程序显示用户输入的3个数字中的最大和最小数字

[英]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.

相关问题 使用数组编写C程序,以从100个随机数的列表中找到最大和最小的数 - Write a C program using array to find largest and smallest number from a list of 100 Random numbers 如何从输入整数中找到最大和最小可能的数字? - How to find the largest and smallest possible number from an input integer? 查找三个输入数字中最大和最小的程序,并显示识别出的最大/最小数字是偶数还是奇数 - program to find the largest and smallest among three entered numbers and also display whether the identified largest/smallest number is even or odd c - 如何在数组中找到最大和最小的数字 - How to find the largest and smallest number in an array in c 如何在C中找到最大和最小的数字 - How to find largest and smallest number in c 如何从用户输入中提取偶数,并在C程序中将它们组合为一个新数 - how to extract the even number from user input, and combine them as a new number in C program 在 c 程序中查找最大数 - Finding largest number in c program 我正在创建一个程序,该程序需要用户输入五次,并使用另一个功能来显示最大的输入 - I'm creating a program that take five input from user and display the largest by using another function 使用C中的指针查找数组中的最大和最小数字 - Find largest and smallest number in array using pointers in C C程序中计算用户输入的次数 - Counting Number Of User Input in C Program
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM