当前位置:网站首页>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;
}边栏推荐
猜你喜欢
随机推荐
Make a row of the dataframe a column name
GNN (graph neural network) introduction vernacular
PTA class a simulated fifth bomb: 1148-1151
JQ获取对象的几种方式
recv & send
Oracle數據庫完全卸載步驟(暫無截圖)
Procédure de désinstallation complète de la base de données Oracle (pas de capture d'écran)
Viwi interface
2022 Anhui province safety officer C certificate examination practice questions simulated examination platform operation
Installing MySQL databases in FreeBSD
Summary of xlnet model
Test questions and answers for the 2022 baby sitter (Level 5) examination
PTA class a simulated ninth bullet: 1114-1117
Basic concepts of machine learning
cyclegan:unpaired image-to-image translation using cycle-consistent adversarial network
Embedded c learning notes
UN make (6) makefile的条件执行
The answer skills and examples of practical cases of the second construction company are full of essence
反向输出一个整数
PTA class a simulated first bomb: 1132-1135









