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

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

Installing MySQL databases in FreeBSD

论文阅读 Exploring Temporal Information for Dynamic Network Embedding

Android system startup security

readv & writev

浅谈接口测试(一)

24. histogram calculation

Textcnn paper Interpretation -- revolutionary neural networks for sense classification

Pixel6 unlock bootloader

28. contour discovery
随机推荐
26. histogram back projection
22. pixel remapping
浅谈接口测试(二)
代码覆盖率测试(一)
recv & send
2022 explosion proof electrical operation certificate examination question bank and simulation examination
Wechat circle of friends test point
pixel 6 root
Eight principles of element positioning
秀场精灵陈梓桐 受邀担任第六季完美童模全球总决赛首席体验官
Redis的使用
recv & send
反向输出一个整数
23. histogram equalization
--SQL of urban cultivation manual -- Chapter 1 basic review
Sunshine boy chenhaotian was invited to be the spokesperson for the global finals of the sixth season perfect children's model
cyclegan:unpaired image-to-image translation using cycle-consistent adversarial network
Interpretation of script corresponding to postman assertion
21. Hoff circle transformation
Common deep learning optimizers