2. (4 marks) Write a C function to find the average of all array elements in an one-dimensional array. The function prototype is as follows, float array_average(float a[], int n); /* find the average of all array elements in array a, and n is the size of array a.
Here I am providing the code and the output for the given problem
Code
Output
Code
#include <stdio.h>
float array_average(float a[] , int n); //function declaration
float array_average(float a[] , int n){ //function
definition
int i;
float sum = 0; //initialising the variables
for(i = 0 ; i < n ; i++) //adding all the elements in the
array
sum+=a[i];
return sum/n; //returning the average of array
}
int main()
{
int n = 9;
float a[9] = {1,2,3,4,5,6,7,8,9}; //declaring one dimensional
array
float result = array_average(a,n); //calling function
array_average
printf("The average of the array is %.2f",result); //displaying the
result
}
Note : Hit Like if you got the correct output. Please comment if you have any doubts.Thank you
2. (4 marks) Write a C function to find the average of all array elements in...
Question 14; Write a C function named isSymmetric, the prototype of which is given below, that returns 1 if the elements of an array of integers named myArray of size n are symmetric around the middle. If the array elements are not symmetric, the function should return 0. Both the array and its size are specified as parameters. (10 marks) Clue: Array myArray of size n is symmetric if myArray[0] is equal to myArray[n-1], myArray[1] is equal to myArray[n-2], and...
Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array is randomly initialized (using Math.random()). Write a method to find the maximum value in this two dimensional array; Write a method to find the average value in the array; Write a method to count how many elements are smaller than average; Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array. Method is...
c++, need help thank you Given an array of ints, return the sum of all elements from the array that come before the first element that equals number 4 in the array. The array will contain at least one 4. Function prototype: int pre4int array ( ], int size); Hint: to find the array size, use: int size = sizeof(array) / sizeof( array[0]); Sample runs: int array1[ ] = {1, 2, 4, 1); pre4(array1, 4); // returns 3 int array2...
Write a function called median that returns the median entry in a 1-dimensional array of integers. For example, if we have an array a={3,4,5,1,6}; then the median entry of this array a is 4. You need to sort the array a first, to get {1,3,4,5,6}, then find the entry in the middle position. If the array size is even, it means that array has even number of elements. For example, a={3,2,4,1}, then first sort it, a becomes {1,2,3,4}, then the...
(C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....
In C language Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function, and displays...
1. Write a C function named find that receives a one-dimensional array of type integer named arr and its size of type integer. The function fills the array with values that are the power of four (4^n) where n is the index. After that, the function must select a random index from the array and move the array elements around the element stored in the randomly selected index Example arr = [1, 4, 16, 64, 256) if the randomly selected...
C++.Write the body of a function that returns the sum of all elements in a two-dimensional array passed to it as an argument. Declare and initialize all needed variables. int arraySum(const int numbers[][COLS], int rows) { }
sort.c #include <stdlib.h> #include <stdio.h> #include "libsort.h" int main() { int* array; int size, c; float median; printf("Enter the array size:\n"); scanf("%d", &size); array = (int*) malloc(size * sizeof(int)); printf("Enter %d integers:\n", size); for (c = 0; c < size; c++) scanf("%d", &array[c]); sort(array, size); printf("Array sorted in ascending order:\n"); for (c = 0; c < size; c++) printf("%d ", array[c]); printf("\n"); median = find_median(array,...
Complere a c++ function that returns the sum of all elements in a two-dimensional array of double's: const int COLUMNS = 5; double sum(double values[][COLUMNS], int rows) {