Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In C please. Provided starter code. just need to write a program to take an integer array, an integer representing the size of the array,
In C please. Provided starter code. just need to write a program to take an integer array, an integer representing the size of the array, and a result pointer. This function will calculate the average of all the elements in the array which are odd, and place the result in the result pointer. The function will return 0 on error, or the number of elements averaged on success. using avgOdd
In this lab, you will cover pass by reference and error codes. You must analyze the problem given, determine what error conditions you may encounter, and make sure you code will not crash if an error condition is encountered. Test data is provided that you may optionally use. The first line in the data file is an integer representing the number of entries in the file, and the following lines are integers between 0 and 100. 1.1 avgOdd int avgOda(int *array, int size, tloat result); Info: This function will take an integer array, an integer representing the size of the array, and a result pointer. This function will calculate the average of all the elements in the array which are odd, and place the result in the result pointer. The function will return 0 on error, or the number of elements averaged on success. #include "lab1.h" int main() { FILE *file = fopen("numbers.txt", "r"); if(!file) { // Unable to open the specified file return EXIT_FAILURE; } int size; if(fscanf(file, "%d", &size) != 1) { fclose(file); 17 Unable to read the array size from the file return EXIT_FAILURE; 3 int array[size]; for(int i 0; iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started