Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- /* defining array members count */
- #define ARRAY_COUNT ((int)10)
- /* delcaring functions */
- void fill_array(int *array);
- void print_array(int *array);
- float find_mean(int *array);
- /* entry point */
- int main(void)
- {
- /* preparing randomizer */
- srand(time(NULL));
- /* declaring array */
- int array[ARRAY_COUNT];
- /* working */
- fill_array(array);
- print_array(array);
- printf("mean: %0.2f\n", find_mean(array));
- /* waiting for exit */
- return system("pause");
- }
- /* filling array with rundom numbers */
- void fill_array(int *array)
- {
- /* we don't want to work with NULLs */
- if (array == NULL)
- {
- printf("Array is NULL pointer\n");
- return;
- }
- /* generating rundoms and writing tham to array */
- for (int i = 0; i < ARRAY_COUNT; i++)
- array[i] = rand() % 100 + 1;
- }
- /* printing array to stdout */
- void print_array(int *array)
- {
- printf("=====\tARRAY\t=====\n");
- /* we don't want to work with NULLs */
- if (array == NULL)
- {
- printf("Array is NULL pointer\n");
- return;
- }
- for (int i = 0; i < ARRAY_COUNT; i++)
- printf("ARR[%2d] = %3d\n", i+1, array[i]);
- printf("=====================\n");
- }
- /* finding mean */
- float find_mean(int *array)
- {
- /* we don't want to work with NULLs */
- if (array == NULL)
- {
- printf("Array is NULL pointer\n");
- return -1;
- }
- float mean = .0;
- int count = 0;
- for (int i = 0; i < ARRAY_COUNT; i++)
- {
- if (array[i] % 2 == 0) {
- mean += array[i];
- count++;
- }
- }
- return mean/count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement