Question

[C++ Language] Write a function to find out the average of an integer array and return...

  1. [C++ Language] Write a function to find out the average of an integer array and return to the main function.

Homework Answers

Answer #1

code:

=================================

#include <iostream>

using namespace std;
float calculateAvg(int A[],int n);
int main() {
int size;
float result;
cout<<"Enter the size of array : ";
cin>>size;
int Arr[size];
cout<<"Enter the array elements: ";
for(int i=0;i<size;i++)
{
cin>>Arr[i];
}
//call average function
result=calculateAvg(Arr,size);
cout<<"The average of array is: "<<result;
}
float calculateAvg(int A[],int n)
{
float avg;
int sum=0;
for(int i=0;i<n;i++)
{
sum=sum+A[i];
}
avg=sum/n;
  
return avg;
}

please upvote

Know the answer?
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
Similar Questions
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns the index of the first occurance of the smallest value in the array. Your function must be able to process all the elements in the array. Create a function prototype and function definition (after the main function). Your main function should declare a 100 element integer array. Prompt the user for the number of integers to enter and then prompt the user for each...
Write a function to print a the MxN array to an output file. in c++ language
Write a function to print a the MxN array to an output file. in c++ language
Use MIPS assembly language program to swap two of the integers in an integer array. The...
Use MIPS assembly language program to swap two of the integers in an integer array. The program should include the Swap function to swap the integers and the main function to call the Swap function. The main function should: • Pass the starting address of the array in $a0. • Pass the indices of the two elements to swap in $a1 and $a2. • Preserve (i.e. push onto the stack) any T registers that it uses. • Call the Swap...
C++ Write a function that takes in 3 arguments: a sorted array, size of the array,...
C++ Write a function that takes in 3 arguments: a sorted array, size of the array, and an integer number. It should return the position where the integer value is found. In case the number does not exist in that array it should return the index where it should have been if it were present in this sorted array. Use pointer notation of arrays for this question. c++ code
Programming in C language (not C++) Write a main function with a function call to a...
Programming in C language (not C++) Write a main function with a function call to a function called Calculation which has two integer arguments/ parameters. The function returns a character. Declare and initialize the necessary data variables and assign balues needed to make it executable and to prevent loss of information. //input 2 integer values //returns the characterequivalent of the higher of the two integer values char Calculation(int, int);
Write a function called "isPrime()” that checks if an integer number is prime or not. The...
Write a function called "isPrime()” that checks if an integer number is prime or not. The function returns integer 1 if the number is prime, or integer 0 if the number is not prime. Write a simple test program in main() to show that the function works properly.in C programming language.
Write a C++ program to perform the following tasks     a) Declare an integer array of...
Write a C++ program to perform the following tasks     a) Declare an integer array of size 1000.     b) Initialize the array with random values between 1 and 9.     c) Write the code to find and print, how many 1’s occur in the array.
C programming Write a function that takes in a 2D char array (string array) and return...
C programming Write a function that takes in a 2D char array (string array) and return a 1D char array with all the elements connected together Hint: strlen(-char*-) //returns the length of a string strcat(-char* accum-, something to add) //works like string+= in java
Write a program in c++ to Convert an array of inches to an array of centimeters....
Write a program in c++ to Convert an array of inches to an array of centimeters. The program should contain a function called inchesTOcm with three parameters (inches array that contains the values in inches, cm array to save the result in, and an integer variable that defines the length of the array). In the main function: 1. Define an array (inches) of length 3. 2. Initialize the array by asking the user to input the values of its elements....
Define a function to find the largest element from an integer array.
Define a function to find the largest element from an integer array.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT