forked from ivan-igorevich/basic-c
34 lines
737 B
C
34 lines
737 B
C
|
#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
|
||
|
int i = 0;
|
||
|
float result = 0;
|
||
|
while (i < ARRAY_LENGTH) {
|
||
|
printf("Enter value %d:", i);
|
||
|
scanf("%d", arr[i]);
|
||
|
i++;
|
||
|
}
|
||
|
printf(“Our array is: ”);
|
||
|
printArray(arr, ARRAY_LENGTH);
|
||
|
printf(“And the average is: %f \n”,
|
||
|
average(arr, ARRAY_LENGTH));
|
||
|
return 0;
|
||
|
}
|