当前位置:网站首页>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;
}边栏推荐
- biggan:large scale gan training for high fidelity natural image synthesis
- Code coverage test (I)
- 2022 documenter general basic (documenter) exam simulation 100 questions and online simulation exam
- PTA class a simulated 11th bomb: 1124-1131
- Abnova丨CSV 单克隆抗体解决方案
- recv & send
- Summary of informer's paper
- PTA class a simulated seventh bomb: 1160-1163
- Basic concepts of machine learning
- leetcode 300. Longest increasing subsequence (medium)
猜你喜欢

readv & writev

Distributed systems (II) understanding of distributed transactions

Android system startup security

--SQL of urban cultivation manual -- Chapter 1 basic review

28. contour discovery

Cross validation -- a story that cannot be explained clearly

One stop solution EMQ for hundreds of millions of communication of Internet of things

tos cos dscp 区别和作用

浅谈接口测试(一)

Interpretation of script corresponding to postman assertion
随机推荐
web测试
UN make (6) makefile的条件执行
字节序问题
Fasttext knowledge points summary
makefile 中export set ENV 的区别和作用
Simple making of master seal
Install tensorflow GPU miscellaneous
Operation of simulated examination platform for electrical test questions in 2022
Android system startup security
CyCa children's physical etiquette Yueqing City training results assessment successfully concluded
Rollback Protection
Procédure de désinstallation complète de la base de données Oracle (pas de capture d'écran)
JQ获取对象的几种方式
wifi 相关知识详解
27. template match
元素定位的八大法则
Show spirit chenzitong was invited to be the chief experience officer of the global finals of the sixth season perfect children's model
pixel 6 root
Pixel6 unlock bootloader
Test questions and answers for the 2022 baby sitter (Level 5) examination