Output from my sorter for n = 2, 3, and 4. - jdp
#include <stdio.h> int main() { int a, b; char *format = "%d %d\n"; printf("Enter 2 numbers\n"); scanf("%d %d", &a, &b); if (a>b) { printf(format, a,b); } else { printf(format, b,a); } } #include <stdio.h> int main() { int a, b, c; char *format = "%d %d %d\n"; printf("Enter 3 numbers\n"); scanf("%d %d %d", &a, &b, &c); if (a>b) { if (b>c) { printf(format, a,b,c); } else { if (a>c) { printf(format, a,c,b); } else { printf(format, c,a,b); } } } else { if (a>c) { printf(format, b,a,c); } else { if (b>c) { printf(format, b,c,a); } else { printf(format, c,b,a); } } } } #include <stdio.h> int main() { int a, b, c, d; char *format = "%d %d %d %d\n"; printf("Enter 4 numbers\n"); scanf("%d %d %d %d", &a, &b, &c, &d); if (a>b) { if (b>c) { if (c>d) { printf(format, a,b,c,d); } else { if (b>d) { printf(format, a,b,d,c); } else { if (a>d) { printf(format, a,d,b,c); } else { printf(format, d,a,b,c); } } } } else { if (a>c) { if (b>d) { printf(format, a,c,b,d); } else { if (c>d) { printf(format, a,c,d,b); } else { if (a>d) { printf(format, a,d,c,b); } else { printf(format, d,a,c,b); } } } } else { if (b>d) { printf(format, c,a,b,d); } else { if (a>d) { printf(format, c,a,d,b); } else { if (c>d) { printf(format, c,d,a,b); } else { printf(format, d,c,a,b); } } } } } } else { if (a>c) { if (c>d) { printf(format, b,a,c,d); } else { if (a>d) { printf(format, b,a,d,c); } else { if (b>d) { printf(format, b,d,a,c); } else { printf(format, d,b,a,c); } } } } else { if (b>c) { if (a>d) { printf(format, b,c,a,d); } else { if (c>d) { printf(format, b,c,d,a); } else { if (b>d) { printf(format, b,d,c,a); } else { printf(format, d,b,c,a); } } } } else { if (a>d) { printf(format, c,b,a,d); } else { if (b>d) { printf(format, c,b,d,a); } else { if (c>d) { printf(format, c,d,b,a); } else { printf(format, d,c,b,a); } } } } } } }