Home > Backend Development > C#.Net Tutorial > How to implement sorting of three numbers in C language

How to implement sorting of three numbers in C language

coldplay.xixi
Release: 2020-06-08 17:13:01
Original
33596 people have browsed it

How to implement sorting of three numbers in C language

# How to implement three number sorting in c language?

C language implements the method of sorting three numbers:

Input three integers a, b, c from the console to implement the three integers The integers are sorted from small to large, and the if statement is used for conditional judgment. If a is greater than b, the values ​​​​of a and b are exchanged with the help of the intermediate variable temp, and so on to compare a and c, b and c, and the final result is a , b, c in ascending order.

Code:

#include <stdio.h>
int main()
{
int a, b, c, temp;
scanf_s("%d%d%d", &a, &b, &c);
if (a > b)
{
temp = a;
a = b;
b = temp;
}
if(a>c)
{
temp = a;
a = c;
c = temp;
}
if (b > c)
{
temp = b;
b = c;
c = temp;
}
printf("%d %d %d", a, b, c);
return 0;
}
Copy after login

Recommended tutorial: "C Video Tutorial"

The above is the detailed content of How to implement sorting of three numbers in C language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
c
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template