当前位置:网站首页>Input 3 integers and output them from large to small
Input 3 integers and output them from large to small
2022-06-26 01:49:00 【So it is^^】
Method 1 :
thought : First find 3 The maximum and minimum number , Then add them up and subtract the maximum and minimum values to find the middle value
#include<stdio.h>
int main()
{
int arr[3] = { 0 }; // Used for holding 3 Put an integer into the array
int sum = 0; // Sum up
int middle = 0; // In the middle
int i = 0;
int min = 2147483647; // Find the minimum
int MAX = -2147483647; // Find the maximum
for (i = 0; i < 3; i++)
{
scanf("%d", &arr[i]);
sum = sum + arr[i]; // Sum up
if (arr[i] > MAX)
{
MAX = arr[i]; // Find the maximum
}
if (arr[i] < min)
{
min=arr[i]; // Find the minimum
}
}
middle = sum - MAX - min; // Add up and subtract the maximum and minimum values to find the middle value
printf("%d %d %d", MAX, middle,min);
return 0;
}Method 2
thought : Put the maximum value in a in , Put the minimum value in c in
#include<stdio.h>
int main()
{
int a = 0; // Put the maximum value in a
int b = 0;
int c = 0; // Put the minimum value in c
int res = 0; // spare
scanf("%d %d %d", &a, &b, &c);
if (a < b) // Compare a and b Which is the big one , And put the big one in a in
{
res = a;
a = b;
b = a;
}
if (a < c) // Compare a and c Which is the big one , And put the big one in a in
{
res = a;
a = c;
c = res;
}
if (c > b) // Compare c and b Which is the smallest , And put the small one in c in
{
res = c;
c = b;
b = res;
}
printf("%d %d %d", a, b, c);
return 0;
}边栏推荐
- GUN make (2) 总述
- xargs 的作用详解
- biggan:large scale gan training for high fidelity natural image synthesis
- Tengwenze, a hot-blooded boy, was invited to serve as the image ambassador of the global finals of the sixth season perfect children's model
- Eight principles of element positioning
- JQ获取对象的几种方式
- Summary of in-depth learning optimization techniques
- Model integration and cascading
- Accumulation of some knowledge points in machine learning
- Operation of simulated examination platform for electrical test questions in 2022
猜你喜欢

Postman断言对应脚本的解释

Textcnn paper Interpretation -- revolutionary neural networks for sense classification

热血男孩滕文泽 受邀担任第六季完美童模全球总决赛形象大使

通俗易懂C语言关键字static

俏皮少女王艺璇 受邀担任第六季完美童模全球总决赛推广大使

GUN make (2) 总述

论文阅读 Exploring Temporal Information for Dynamic Network Embedding

王老吉药业“关爱烈日下最可爱的人”公益活动在杭启动

Explication du script correspondant à l'assertion Postman

Android system startup security
随机推荐
biggan:large scale gan training for high fidelity natural image synthesis
27. template match
求n的乘阶
浅谈接口测试(二)
Xiaomi tablet 5 Pro unlock bootloader
wifi 的理论速度计算方法
PTA class a simulated second bullet: 1136-1139
APP测试与WEB测试的区别
recv & send
Cross validation -- a story that cannot be explained clearly
App test (I)
PTA class a simulated 8th bomb: 1164-1167
Summary of xlnet model
Data arrangement of machinetranslation
JQ获取对象的几种方式
Wechat circle of friends test point
Common deep learning optimizers
弹性蛋白酶的用途和化学性质
2022 documenter general basic (documenter) exam simulation 100 questions and online simulation exam
Talking about interface test (2)