当前位置:网站首页>输入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;
}边栏推荐
猜你喜欢

Principle of voice wake-up

Can bus transceiver principle

浅谈接口测试(一)

Exploring temporary information for dynamic network embedding

"Hot post" Statistics

Cross validation -- a story that cannot be explained clearly

Shell regular expression

Basic concepts of machine learning

GUN make (2) 总述

Obtain WiFi password through computer (only connected WiFi)
随机推荐
论文阅读 Exploring Temporal Information for Dynamic Network Embedding
PTA class a simulated second bullet: 1136-1139
Interpretation of script corresponding to postman assertion
Several methods of JQ obtaining objects
Complete review (including syntax) -- MySQL regular expressions
大周建议自媒体博主前期做这4件事
Abnova丨抗GBA单克隆抗体解决方案
APP测试与WEB测试的区别
Pixel6 unlock bootloader
Some summary of sequence model
Maze walking
Talking about interface test (I)
二造实务案例答题技巧和举例汇总,满满都是精髓
Quickly generate 1~20 natural numbers and easily copy
PTA class a simulation bomb 10: 1119-1123
wifi 相关知识详解
Rollback Protection
Abnova丨CMV CISH 探头解决方案
22. pixel remapping
User unlock status query