I have been trying to get an array to sort out 4 numbers that someone enters in. I have been reading on how to do this but nothing will work...
This program is supposed to sort the numbers in ascending and descending order.
This is what I have so far. I'm trying to get them to ascend right now but I'm failing.
This program is supposed to sort the numbers in ascending and descending order.
This is what I have so far. I'm trying to get them to ascend right now but I'm failing.
Code:
#include "stdafx.h" #define ARY_SIZE 4 int main(void) { printf ("Welcome please enjoy this program.\n\n"); int num [ARY_SIZE]; int i; int j; int x; printf ("Enter 4 numbers please.\n"); for (int i = 0; i < ARY_SIZE; i++) scanf("%d", &num [i]); { for (int j = i+1; j < ARY_SIZE; j++) { if (num[i] > num[j]) { x = num[i]; num[i] = num[j]; num[j] = x; } } } return 0; }
Comment