I have two stylistic suggestions:
- Place your closing braces on their own lines. This is more conventional.
- Have your function prototypes match the function definitions, including the parameter names. This makes them more readable.
For example:
Code:
#include <stdio.h>
#include <stdlib.h>
void sortA(int anSrt[], int nSize);
void sortD(int anSrt[], int nSize);
void swap(int *a, int *b);
int main(){
int anStore[10] = {0};
int nChoice;
int x;
for(x=0; x<10; x++) {
printf("\nPlease insert numbers: ");
scanf("%d", &anStore[x]);
}
printf("Please choose sorting options: \n1.\tAscending\n2.\tDescending\n\nChoice: ");
scanf("%d", &nChoice);
switch(nChoice){
case 1:{ sortA(anStore, 10); } break;
case 2:{ sortD(anStore, 10); } break;
}
printf("Numbers after sorting are...\n\n");
int y;
for(y=0; y<10; y++){
printf("%d\n", anStore[y]);
}
}
void sortA(int anSrt[], int nSize){
int x, y;
for(y=0; y<nSize; y++){
for(x=0; x<nSize; x++){
if(anSrt[x] > anSrt[y])
swap(&anSrt[y], &anSrt[x]);
}
}
}
void sortD(int anSrt[], int nSize){
int x, y;
for(y=0; y<nSize; y++){
for(x=0; x<nSize; x++){
if(anSrt[x] < anSrt[y])
swap(&anSrt[y], &anSrt[x]);
}
}
}
void swap(int *a, int *b){
int store;
store = *a;
*a = *b;
*b = store;
}