当前位置:网站首页>输入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;
}边栏推荐
- Is it safe to log in the stock account on the flush? How to open a stock account in the flush
- Several methods of JQ obtaining objects
- APP测试与WEB测试的区别
- **MySQL例题一(根据不同问题,多条件查询)**
- 26. histogram back projection
- GNN (graph neural network) introduction vernacular
- 2022 documenter general basic (documenter) exam simulation 100 questions and online simulation exam
- Common basic Oracle commands
- 论文阅读 Exploring Temporal Information for Dynamic Network Embedding
- 胰蛋白酶的化学性质及应用
猜你喜欢

Xiaomi tablet 5 Pro unlock bootloader

Postman断言对应脚本的解释

从在浏览器的输入框输入一个网址,到看到网页的内容,这个过程中发生了什么?

物联网亿万级通信一站式解决方案EMQ

The overall process of adding, deleting, modifying and querying function items realized by super detailed SSM framework

CityJSON

蒟蒻初学单片机的一丢丢笔记

Explication du script correspondant à l'assertion Postman

28. contour discovery

tos cos dscp 区别和作用
随机推荐
APP测试与WEB测试的区别
pixel 6 root
PTA class a simulated third bomb: 1140-1143
丨EGFR FISH 探针解决方案
2022 Anhui province safety officer C certificate examination practice questions simulated examination platform operation
xargs 的作用详解
GUN make (5) makefile中的变量
Abnova丨ACTN4 DNA 探针解决方案
热血男孩滕文泽 受邀担任第六季完美童模全球总决赛形象大使
Dataframe converts the data type of a column
王老吉药业“关爱烈日下最可爱的人”公益活动在杭启动
Shell regular expression
Test questions and answers for the 2022 baby sitter (Level 5) examination
MySQL book borrowing system project database creation TABLE statement (combined primary key and foreign key settings)
2021-1-15 摸鱼做的笔记Ctrl+c /v来的
Several methods of JQ obtaining objects
26. histogram back projection
Make a row of the dataframe a column name
Log4j2 vulnerability
论文阅读 Exploring Temporal Information for Dynamic Network Embedding