Problem Description
输入三个整数,找出其中的中间数。(这里的中间数指的是大小,不是位置。)
Input
输入3个整数。
Output
输出中间数。
Example Input
1 2 3
Example Output
2
#include <stdio.h>
void main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if((b<=a && a<=c) ||(c<=a && a<=b))
printf("%d\n",a);
else if((a<=b && b<=c)||(c<=b && b<=a))
printf("%d\n",b);
else if((a<=c && c<=b) ||(b<=c && c<=a))
printf("%d\n",c);
}
或者
#include<stdio.h>
int main()
{
int a,b,c,t;
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{t=a;a=b;b=t;}
if(a>c)
{t=a;a=c;c=t;}
if(b>c)
{t=b;b=c;c=t;}
printf("%d",b);
return 0;
}
这篇博客介绍了如何使用C语言解决找到三个整数中居中的数的问题。提供了两种不同的实现方法,通过条件判断和排序来找出中位数。
2529

被折叠的 条评论
为什么被折叠?



