In C Write a couple of functions to process arrays. Note that from the description of the function you have to identify what would be the return type and what would be part of the parameter.
display(): The function takes an int array and it’s size and prints the data in the array.
sumArray(): It takes an int array and size, and returns the sum of the elements of the array.
findMax(): It takes an int array and size, and returns the maximum value in the array.
getDouble(): it takes an int data (not an array) and returns the double of the data passed to it. For example, if you pass 5, it returns 10 (as 10 = 5*2)
In the main function:
#define SIZE 5
Declare an array of size SIZE and take user inputs to store in the array.
Then call the display function with the array that prints the array
Then call sumArray() function and print the sum returned from the sumArray() function
Then call findMax() function and print the max value returned from the function
Then for each element of the array call the getDouble() function and print the returned value in the main function
Now, declare another array of the same size and put the data from your first array to the second array in reverse order.
Call all the functions above using the second array and they should also display the same information except the display function that display the data in reverse order.
Sample input/output:
Enter number 1: 50
Enter number 2: 40 Enter number 3:
30 Enter number 4: 20
Enter number 5: 10
50 40 30 20 10
The sum of myArray is: 150
The max value of myArray is: 50
Double of 50 is 100
Double of 40 is 80
Double of 30 is 60
Double of 20 is 40
Double of 10 is 20
Now the following data are from RevArray 10 20 30 40 50
The sum of revArray is: 150
The max value of revArray is: 50
Double of 10 is 20
Double of 20 is 40
Double of 30 is 60
Double of 40 is 80
Double of 50 is 100
C CODE STARTs :
#include <stdio.h>
#define size 5
void display(int arr1[size])
{
int i;
for (i=0;i<size;i++)
printf("%d\t",arr1[i]);
}
int sumArray(int arr1[size])
{
int sum = 0, i;
for (i=0;i<size;i++)
sum = sum + arr1[i];
return sum;
}
int findMax(int arr1[size])
{
int max = arr1[0],i;
for (i=0;i<size;i++)
if (arr1[i]>max)
max = arr1[i];
return max;
}
int getDouble(int a)
{
return a*2;
}
void main()
{
int arr[size] , i ,j, sum ,max;
for ( i = 0 ; i < size ; i++)
{
printf("Enter Number %d :",i+1);
scanf("%d",&arr[i]);
}
display(arr);
sum = sumArray(arr);
printf("\nThe Sum Of myArray is %d\n",sum);
max = findMax(arr);
printf("\nThe Max value of Array is %d\n",max);
for (i=0;i<size;i++)
printf("\nDouble of %d is %d\n",arr[i],getDouble(arr[i]));
int arr2[size];
for (j=size-1,i=0;j>=0,i<size;j--,i++)
arr2[i]=arr[j];
display(arr2);
sum = sumArray(arr2);
printf("\nThe Sum Of myArray is %d\n",sum);
max = findMax(arr2);
printf("\nThe Max value of Array is %d\n",max);
for (i=0;i<size;i++)
printf("\nDouble of %d is
%d\n",arr2[i],getDouble(arr2[i]));
}
OUTPUT :
Enter Number 1 :50
Enter Number 2 :40
Enter Number 3 :30
Enter Number 4 :20
Enter Number 5 :10
50 40 30 20 10
The Sum Of myArray is 150
The Max value of Array is 50
Double of 50 is 100
Double of 40 is 80
Double of 30 is 60
Double of 20 is 40
Double of 10 is 20
10 20 30 40 50
The Sum Of myArray is 150
The Max value of Array is 50
Double of 10 is 20
Double of 20 is 40
Double of 30 is 60
Double of 40 is 80
Double of 50 is 100
Image of the output:

Hope this may help you
Thank you ??
In C Write a couple of functions to process arrays. Note that from the description of...
c/c++
Passing arrays as arguments to functions. The main() is given, write the function 'average' (Study the syntax of passing an array as a function parameter) The program prompts the user to first enter the number of tests given in a course, and then prompts him/her to enter the mark for each test. The marks are stored in an array. This takes place in the main() function. It then passes the array to a function named 'average' that calculates and...
**IN C***
*
In this lab, you will write a program with three recursive functions you will call in your main. For the purposes of this lab, keep all functions in a single source file: main.c Here are the three functions you will write. For each function, the output example is for this array: int array[ ] = { 35, 25, 20, 15, 10 }; • Function 1: This function is named printReverse(). It takes in an array of integers...
C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...
Develop a system flowchart and then write a menu-driven C++ program that uses user-defined functions arrays, and a random number generator. Upon program execution, the screen will be cleared and the menu shown below will appear at the top of the screen and centered. The menu items are explained below. Help Smallest Quit H or h ( for Help ) option will invoke a function named help() which will display a help screen. The help screen(s) should guide the user...
C++ Code Pass By Reference Practice Write the following functions for basic array operations based on the function descriptions given below. Write the following functions for basic array operations based on the function descriptions given below. FindMinArray: This function will search an array of integers (passed to the function as a parameter) for its minimum value, then return that value. SumArray: This function will sum an array of integers (passed to the function through a parameter) then return that sum....
for this assignment you will be creating a series of functions for manipulating an array of data. The data will consist of randomly generated doubles. You should make the following functions: generate() - This function fills an array with random doubles in a specified range. This function takes four inputs: an array of doubles, an integer representing the size of the array, and two doubles representing the lower an upper bounds of the range random values. For example, the function...
You are to write three functions for this lab: mean, remove, display. Download the main.cpp file provided to get started. Read the comments in the main function to determine exactly what the main function should do. //include any standard libraries needed // - Passes in an array along with the size of the array. // - Returns the mean of all values stored in the array. double mean(const double array[], int arraySize); // - Passes in an array, the size...
Create a program that creates an array of 500 random numbers between -10 and 10. Write several functions: Function 1 - prints the array with a certain number of elements per line. Prototype: void printArray(int array[], int numElements, int numPerLine, ostream &os) Function 2 prints only the array elements that are evenly divisible by an input number. Prototype: void printDivBy(int array[], int numElements, int numPerLine, int divBy, ostream &os) Function 3 takes the input array and returns the maximum, the...
#include <stdio.h>
// Define other functions here to process the filled array: average, max, min, sort, search
// Define computeAvg here
// Define findMax here
// Define findMin here
// Define selectionSort here ( copy from zyBooks 11.6.1 )
// Define binarySearch here
int main(void) {
// Declare variables
FILE* inFile = NULL; // File pointer
int singleNum; // Data value read from file
int valuesRead; // Number of data values read in by fscanf
int counter=0; // Counter of...
// PLACE YOUR NAME HERE #include <iostream> using namespace std; float findAverage (int [], int); // finds average of all //grades int findHighest (int [], int); // finds highest of all //grades int findFirstFail( int[]); int main() { int grades[100]; // the array holding 100 grades. int numberOfGrades; // the number of grades read. int pos; // index to the array. float avgOfGrades; // contains the average of the grades. int highestGrade; // contains the highest grade. int inderOfFail; //...