Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C language Project: You will create a program which contains 4 functions: 1)

ID: 3810527 • Letter: I

Question

In C language

Project: You will create a program which contains 4 functions: 1) Read Array 2) Find MaxValue 3) Reverse Array 4) Print Array When the main0 executes it will only have calls to 4 functions listed above. ReadArray0 prompts user to enter up to 10 integers. When a 0 is entered, it will signal the end of user input. FindMaxValue0 finds the highest value from the array. ReverseArray() keeps track of how many elements are there in the array and reverses the array and storing in another array which is also passed to it by main Finally, PrintArray() prints the new reversed array. You will declare your arrays in the main function, initialize to contain zeroes(0) and pass them as arguments to each function that requires to operate on them. You shall use pointers to arrays to pass the arrays to the functions. Within all the functions you will use pointers to accomplish the function task. The book has examples programs for each of those. Use those examples to help you in completing the assignment Ensure that you provide the prototypes for each function, then write your main function followed by the 4 functions. Each function should have a comment box at the top as described in Chapter 10 examples in the book You will ensure that the return values and the parameters for each function are well thought out and added to barebones function declaration mentioned above.

Explanation / Answer

#include <stdio.h>
#include <string.h>
void ReadArray(int *a, int *n){
int i;
printf("Enter the series of the numbers terminated by a 0: ");
for(i =0; i<*n; i++){
scanf("%d", &*(a + i));
if(*(a + i) == 0){
*n = i;
break;
}
}
}
int FindMaxValue(int *a, int n) {
int i;
int max = *(a+0);
for(i =0; i<n; i++){
if(max < *(a+i)){
max = *(a+i);
}
}
return max;
}
void ReverseArray(int *a, int n) {
int i, temp;
for(i=0; i<n/2; i++){
temp = *(a+i);
*(a+i) = *(a+n-1-i);
*(a+n-1-i) = temp;
}
  
}
void PrintArray(int *a, int n){
int i;
for(i=0; i<n; i++) {
printf("%d ", *(a+i));
}
printf(" ");
  
}
int main()
{
int n = 10;
int max;
int a[10] = {0,0,0,0,0,0,0,0,0,0};
ReadArray(a, &n);
max = FindMaxValue(a, n);
printf("The highest element in an array s %d ", max);
ReverseArray(a,n);
PrintArray(a,n);

return 0;
}

Output:

sh-4.2$ gcc -o main *.c                                                                                                                                                                                                                                                  

sh-4.2$ main                                                                                                                                                                                                                                                             

Enter the series of the numbers terminated by a 0:                                                                                                                                                                                                                       

34 56 78 11 4 1 99 0                                                                                                                                                                                                                                                     

The highest element in an array s 99                                                                                                                                                                                                                                     

99 1 4 11 78 56 34