Home >Backend Development >C#.Net Tutorial >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; }
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!