只有3个数,穷举比较实现很方便,所以在输入3个数后直接利用if...else if结构比较大小取中值输出即可。代码如下:
#include "stdio.h"
int main(int argc,char *argv[]){
int a,b,c;
printf("Input 3 integers...\n");
scanf("%d%d%d",&a,&b,&c);
printf("In the middle of the number is ");
if(a>=b && b>=c || c>=b && b>=a)
printf("%d\n",b);
else if(b>=a && a>=c || c>=a && a>=b)
printf("%d\n",a);
else
printf("%d\n",c);
return 0;
}
运行样例如下:
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/ac345982b2b7d0a20ad05111c1ef76094b369a24?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)