Omg can someone please inform me on how I can sort 3 integers only with basic commands like printf, scanf, and if statements? No looping or switches.
I tried heaps of things, creating high and low integers but this is what I've got at the moment:
Code:#include <stdio.h> int main (int argc, char *argv[]) { int a, b, c; printf("Please enter 3 integers: "); scanf("%d, %d, %d", &a, &b, &c); //Determine highest if ( (a > b) && (a > c) && (b > c ) ) { /* for a, b, c */ printf(" Your numbers in order are: %d %d %d\n ", a, b, c); } if ( (b > a) && (b > c) && (c < a) ) { /* for b, a, c */ printf(" Your numbers in order are: %d %d %d\n ", b, a, c); } if ( (a > c) && (a > b) && (c > b) ) { printf(" Your numbers in order are %d %d %d\n", a, c, b); /* for a, c, b */ } if ( (b > a) && (b > c) && (c > a) ) { printf("Your numbers in order are %d %d %d\n", b, c, a); /* for b, c, a */ } if ( (c > a) && (c > b) && (a > b) ) { printf("Your numbers in order are %d %d %d\n", c, a, b); /* for c, a, b */ } if ( (c > a) && (c > b) && (b > a) ) { printf("Your numbers in order are %d %d %d\n", c, b, a); /* for c, b, a */ } return 0; }



LinkBack URL
About LinkBacks



) 