当前位置:网站首页>输入3个整数,从大到小输出出来
输入3个整数,从大到小输出出来
2022-06-26 00:13:00 【原来是这样^^】
方法一:
思想:先找到3个数的最大值和最小值,然后将他们加起来减去最大值和最小值就可以求出中间值
#include<stdio.h>
int main()
{
int arr[3] = { 0 }; //用于把3个整数放进数组里
int sum = 0; //求和
int middle = 0; //中间值
int i = 0;
int min = 2147483647; //找最小值
int MAX = -2147483647; //找最大值
for (i = 0; i < 3; i++)
{
scanf("%d", &arr[i]);
sum = sum + arr[i]; //求和
if (arr[i] > MAX)
{
MAX = arr[i]; //找最大值
}
if (arr[i] < min)
{
min=arr[i]; //找最小值
}
}
middle = sum - MAX - min; //加起来减去最大值和最小值就可以求出中间值
printf("%d %d %d", MAX, middle,min);
return 0;
}方法二
思想:将最大值放入a中,将最小值放入c中
#include<stdio.h>
int main()
{
int a = 0; //将最大值放在a
int b = 0;
int c = 0; //将最小值放在c
int res = 0; //备用
scanf("%d %d %d", &a, &b, &c);
if (a < b) //比较a和b哪个大,并将大的那个放入a中
{
res = a;
a = b;
b = a;
}
if (a < c) //比较a和c哪个大,并将大的那个放入a中
{
res = a;
a = c;
c = res;
}
if (c > b) //比较c和b哪个最小,并将小的那个放入c中
{
res = c;
c = b;
b = res;
}
printf("%d %d %d", a, b, c);
return 0;
}边栏推荐
- 20. Hough line transformation
- MySQL图书借阅系统项目数据库建库表语句(组合主键、外键设置)
- MySQL book borrowing system project database creation TABLE statement (combined primary key and foreign key settings)
- Accumulation of some knowledge points in machine learning
- Simple making of master seal
- Explication du script correspondant à l'assertion Postman
- Is it safe to log in the stock account on the flush? How to open a stock account in the flush
- 27. template match
- GUN make (1) 简介
- 王老吉药业“关爱烈日下最可爱的人”公益活动在杭启动
猜你喜欢
随机推荐
JSON instance (I)
pixel 6 root
readv & writev
**MySQL例题一(根据不同问题,多条件查询)**
RT thread project engineering construction and configuration - (Env kconfig)
Can bus transceiver principle
Quickly generate 1~20 natural numbers and easily copy
recvmsg & sendmsg
CYCA少儿形体礼仪 乐清市培训成果考核圆满落幕
APP测试(一)
通过电脑获取WIFI密码(只能连接过的WiFi)
17.11 std::atomic续谈、std::async深入谈
Test questions and answers for the 2022 baby sitter (Level 5) examination
缓冲
Worthington胶原蛋白酶的多类型研究
cyclegan:unpaired image-to-image translation using cycle-consistent adversarial network
Is it safe to log in the stock account on the flush? How to open a stock account in the flush
JQ 自定义属性取值
正则表达式
判定积分给业务带来价值的两个指标








