|
|
|
@ -4,7 +4,7 @@
|
|
|
|
|
void getInputArr(int *arrSize, int **arr);
|
|
|
|
|
void println(char *printString, float printNum);
|
|
|
|
|
int findMax(int arr[], int arrSize);
|
|
|
|
|
float calcAverage(int arr[], int arrSize);
|
|
|
|
|
float calcAverage(int *arr, int arrSize);
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
int arr[] = {10, 20, 30, 40, 50};
|
|
|
|
@ -25,9 +25,11 @@ int main() {
|
|
|
|
|
getInputArr(&myArrSize, &myArr);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < myArrSize; i++) {
|
|
|
|
|
printf("Element No.%i: %i\n", i, myArr[i]);
|
|
|
|
|
printf("Element No.%i: %i\n", i, myArr[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
println("Average of Elements in Dynamic MyArray: ", calcAverage(myArr, myArrSize));
|
|
|
|
|
|
|
|
|
|
free(myArr);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -36,11 +38,11 @@ void getInputArr(int *arrSize, int **myArr) {
|
|
|
|
|
printf("Please Enter Length of Array: \n");
|
|
|
|
|
scanf("%i", arrSize);
|
|
|
|
|
|
|
|
|
|
*myArr = (int *) malloc(*arrSize * sizeof(int));
|
|
|
|
|
*myArr = malloc(*arrSize * sizeof(int));
|
|
|
|
|
|
|
|
|
|
printf("Enter %i Numbers!\n", *arrSize);
|
|
|
|
|
for (int i = 0; i < *arrSize; i++) {
|
|
|
|
|
scanf("%i", &((*myArr)[i]));
|
|
|
|
|
scanf("%i", &((*myArr)[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -51,17 +53,17 @@ void println(char *printString, float printNum) {
|
|
|
|
|
int findMax(int arr[], int arrSize) {
|
|
|
|
|
int max = arr[0];
|
|
|
|
|
for (int i = 1; i < arrSize; i++) {
|
|
|
|
|
if (arr[i] >= max) {
|
|
|
|
|
max = arr[i];
|
|
|
|
|
}
|
|
|
|
|
if (arr[i] >= max) {
|
|
|
|
|
max = arr[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float calcAverage(int arr[], int arrSize) {
|
|
|
|
|
float calcAverage(int *arr, int arrSize) {
|
|
|
|
|
int sum = 0;
|
|
|
|
|
for (int i = 0; i < arrSize; i++) {
|
|
|
|
|
sum += arr[i];
|
|
|
|
|
sum += arr[i];
|
|
|
|
|
}
|
|
|
|
|
return sum / arrSize;
|
|
|
|
|
return (float) sum / arrSize;
|
|
|
|
|
}
|