#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
void averageAndCountEven(int arr[], int len, double *average, int *count);
void app_main() {
// Declaring and initializing an integer array
int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
// Calculating the length of the array
//swapped (arr) and arr[0] to find the length of the array by dividing the total size by the bytes of each variable TGH
int len = sizeof(arr) / sizeof(arr[0]);
// Declaring average and count variables (not pointers TGH)
double average;
int count;
/* Calling averageAndCountEven(), passing the 'arr' array, length of the array'len',
references to the variables 'average' and 'count', and printing the results */
//calling properly with & symbols to receive the data from the pointers
averageAndCountEven(arr, len, &average, &count);
//made average and count variables because the function is already called above and until changed will display the value of the pointers TGH
printf("The average of array elements is %f\n", average);
printf("The count of even numbers in the array is %d\n", count);
}
/************************
Function - averageAndCountEven
Description - calculates the average and count of even numbers in an integer array
Parameters - arr[] - an integer array
len - length of the array arr[] (number of elements in the array)
average - a pointer to store the average
count - a pointer to store the count
Return type - none
************************/
void averageAndCountEven(int arr[], int len, double *average, int *count) {
//initializing the pointers to 0
*average = 0;
*count = 0;
//loop through the arr[] using 'len' variable as the limit of the integer 'i'
//I set up the loop properly using the following to loop I until len is no longer bigger TGH
for (int i=0; i < len; i++) {
//calculating the total sum and store it in the pointer 'average'
*average += arr[i];
if (arr[i] % 2 == 0) {
(*count)++;
}
}
//calculate the average and store it in the pointer 'average'
//average is divided by len and returned to where it gets called TGH
*average /= len;
}