Question

In C Write a couple of functions to process arrays. Note that from the description of...

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.

  1. display(): The function takes an int array and it’s size and prints the data in the array.

  2. sumArray(): It takes an int array and size, and returns the sum of the elements of the array.

  3. findMax(): It takes an int array and size, and returns the maximum value in the array.

  4. 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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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 ??

Add a comment
Know the answer?
Add Answer to:
In C Write a couple of functions to process arrays. Note that from the description of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c/c++ Passing arrays as arguments to functions. The main() is given, write the function 'average' (Study...

    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...

    **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[]) L...

    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...

  • C++ Code Pass By Reference Practice Write the following functions for basic array operations based on...

    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....

  • You are to write three functions for this lab: mean, remove, display. Download the main.cpp file...

    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...

  • #include <stdio.h> // Define other functions here to process the filled array: average, max, min, sort,...

    #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); //...

    // 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; //...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

  • For this c++ assignment, Overview write a program that will process two sets of numeric information....

    For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....

  • Use two files for this lab: your C program file, and a separate text file containing...

    Use two files for this lab: your C program file, and a separate text file containing the integer data values to process. Use a while loop to read one data value each time until all values in the file have been read, and you should design your program so that your while loop can handle a file of any size. You may assume that there are no more than 50 data values in the file. Save each value read from...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT