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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#pragma warning(disable:4996)
#include <stdio.h>
#define SENTINEL -1
int fillArray(float []);
void printArray(float[], int, float);
float computeSum(float[], int);
float computeMean(float[], int);
void sortArray(float[], int);
void main()
{
float theArray [20];
int arraySize;
float arraySum;
float arrayMean;
arraySize = fillArray(theArray)-1;
arraySum = computeSum(theArray, arraySize);
arrayMean = computeMean(theArray, arraySize);
printArray(theArray, arraySize, arraySum, arrayMean);
sortArray(theArray, arraySize);
getchar();
getchar();
}
int fillArray(float theArray[20])
{
int counter = 0;
float userInput;
do{
printf("Enter a value for the array (Index = [%d]:", counter);
scanf("%f", &userInput);
theArray[counter] = userInput;
counter++;
}
while
(
userInput != SENTINEL
);
return counter;
}
float computeSum(float theArray[20], int arraySize)
{
int i;
float arraySum = 0;
for(i=0, i<arraySum, i++)
{
arraySum = arraySum+theArray[1];
return arraySum;
}
}
float computeMean(float arraySum, int arraySize)
{
float arrayMean;
arrayMean = arraySum/arraySize;
return arrayMean;
}
void printArray (float theArray[20], int arraySize)
{
int i;
printf("The array is as follows:\n");
for(i=0, i<arraySize, i++)
printf("%f", theArray[i]);
printf("\n\nThe sum of the array is %2 if", arraySum);
printf("\n\nThe mean of the array is %2 if", arrayMean);
}
void sortArray(float theArray[20], int arraySize)
{
int i;
int j;
for(j=0, j<arraySize-1, j++)
{
for(j=0, j<arraySize, j++)
{
if (theArray[j]>theArray[j+1])
{
temp = theArray[j+1];
theArray[j+1]= theArray[j];
theArray[j] = temp
}
}
}
printf("\n\n");
for(i=0, i<arraySize, i++)
printf("%2 if", theArray[i]);
}
| |