Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Could you do that in C language? I need to do programming with Recursion and Recursive Functions Here is the code we got #include int
Could you do that in C language?
I need to do programming with Recursion and Recursive Functions
Here is the code we got
#includec. [Finding the sum of elements of an array] For this question, you need to implement two functions i. Write a function which reads the numbers from the file and fills the array and returns the size of the array. The format of the file is as follows: the first number indicates how many numbers, the array should keep. For example, the following file, has 5 numbers and the array should be filled with the values 53, 23, 85, 90, 30. The numbers are separated by space. 5 53 23 85 90 30 The header of the function should be int fillTheArrayFromFile(char fileNameD, int arrayD); HANDLING ERROR] in case the program can't open the file successfully, the function should return -1 [ASSUMPTION] The file can have at most 20 numbers ii. Write a recursive function which takes an input array and its star t and end indices and returns the sum of the elements of the array in the range [startlndex, endlndex]. The function header should be: int sum(int arrayl, int startindex, int endlndex); The main program MUST be as follows (and MUST NOT be changed at all)int fillTheArrayFromFile(char fileName[], int array[]); int sum(int array[], int startIndex, int endIndex); int main(void) { char fileName[100]; printf("Please enter the file name: "); gets(fileName); int array[20]; int arraySize = fillTheArrayFromFile(fileName, array); if (arraySize == -1) { // checking the error condition printf("Error in reading the file. "); return 1; } int result; result = sum(array, 0, arraySize - 1); printf("the summation of the elements of the array is %d", result); return 0; } // to be completed by you :) int fillTheArrayFromFile(char fileName[], int array[]) {} int sum(int array[], int startIndex, int endIndex) {}
Step 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