1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <stdlib.h>
#include <stdio.h>
double inputData(double data[], int *pDataCount) {
printf("Enter a double value: ");
scanf("%lf", &data[*pDataCount]);
(*pDataCount)++;
return data[*pDataCount - 1];
}
void displayArray(double data[], int dataCount) {
int i = 0;
for (i = 0; i < dataCount; i++) {
printf("%lf \n", data[i]);
}
}
void sortArray(double data[], int dataCount){
int i, j, length;
double temp;
length = dataCount;
for ( j = (length - 1); j > 0; j--) {
for (i = 0; i < dataCount; i++) {
if (data[i] > data[i + 1]) {
temp = data[i];
data[i] = data[i+1];
data[i + 1] = temp;
}
}
dataCount--;
}
}
main() {
double myArray[100], input;
int dataCount = 0, arraySize, j;
printf("How big is your array? ");
scanf("%i", &arraySize);
for (j = 0; j < arraySize; j++) {
input = inputData(myArray, &dataCount);
}
sortArray(myArray, dataCount);
displayArray(myArray, dataCount);
system("Pause");
}
|