2021-09-17 14:03:47 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
void printArray(int* array, int length) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
printf("%d ", array[i]);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
float average(int* array, int length) {
|
|
|
|
float result = 0;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
result += *(array + i);
|
|
|
|
return result / length;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, const char** argv) {
|
|
|
|
#define ARRAY_LENGTH 10
|
2021-09-28 00:14:17 +03:00
|
|
|
int arr[ARRAY_LENGTH];
|
2021-09-17 14:03:47 +03:00
|
|
|
int i = 0;
|
|
|
|
float result = 0;
|
|
|
|
while (i < ARRAY_LENGTH) {
|
|
|
|
printf("Enter value %d:", i);
|
2021-09-28 00:14:17 +03:00
|
|
|
scanf("%d", &arr[i]);
|
2021-09-17 14:03:47 +03:00
|
|
|
i++;
|
|
|
|
}
|
2021-09-17 14:26:35 +03:00
|
|
|
printf("Our array is: ");
|
2021-09-17 14:03:47 +03:00
|
|
|
printArray(arr, ARRAY_LENGTH);
|
2021-09-17 14:26:35 +03:00
|
|
|
printf("And the average is: %f \n",
|
2021-09-17 14:03:47 +03:00
|
|
|
average(arr, ARRAY_LENGTH));
|
|
|
|
return 0;
|
|
|
|
}
|