Question

In: Computer Science

write a function mean_value that accepts up to four integers and returns their possibly floating point...

write a function mean_value that accepts up to four integers and returns their possibly floating point mean_value. the function should be able to work with any number of inputs from one to four. ( it just returns the input if there is only one)

Solutions

Expert Solution

#include<iostream>
using namespace std;

float mean_value(int nums[],int size)
{
   int sum=0;
   float mean;
   if(size==1)
   {
   return nums[0];
   }
   else
   {
for(int i=0;i<size;i++)
{
sum=sum+nums[i];
}
mean=(float)sum/size;
return mean;
   }
}

int main()
{
int *nums;
int size;

cout<<"Enter number of integers : ";
cin>>size;
if(size<1 || size>4)
{
cout<<"\nInvalid number of integers either enter 1 or 2 or 3 or 4 not other number. \n";
}
else
{
cout<<endl;
nums=new int[size];

for(int i=0;i<size;i++)
{
cout<<"Enter Number "<<i+1<<" : ";
cin>>nums[i];
}

float mean=mean_value(nums,size);

cout<<"\nMean : "<<mean<<endl<<endl;
}
system("pause");
return 0;
}


Related Solutions

In Java Write a method called findMax that accepts three floating-point number as parameters and returns...
In Java Write a method called findMax that accepts three floating-point number as parameters and returns the largest one.(hints: use conditional statement in the method)
/** * Write a recursive function that accepts a stack of integers and * replaces each...
/** * Write a recursive function that accepts a stack of integers and * replaces each int with two copies of that integer. For example, * calling repeatStack and passing in a stack of { 1, 2, 3} would change * the stack to hold { 1, 1, 2, 2, 3, 3}. Do not use any loops. Do not use * any data structures other than the stack passed in as a parameter. * @param stack */ public static void...
1) Write a function searchValue that accepts an array of integers, the size of the array,...
1) Write a function searchValue that accepts an array of integers, the size of the array, and an integer. Find the last occurrence of the integer passed in as an input argument in the array. Return the index of the last occurrence of the value. If the value is not found, return a -1 2) Write the line of code to call the previous function assuming you have an array vec with length n, and are looking for the number...
Write a Scheme function that takes a list of integers and returns all odd integers on...
Write a Scheme function that takes a list of integers and returns all odd integers on the list in the original order: (odd-numbers `(2 4 9 16 25 7)) (9 25 7) Hint: 2 (remainder 13 5) 3 Please explain every step
In this third part, write a function that accepts an array of integers and its size as arguments.
in C++In this third part, write a function that accepts an array of integers and its size as arguments. The function should create a new array that is of half size the argument array (round up the fraction if the size of the argument array is odd). The value of the first element (Element 0) of the new array should be the sum of the first two elements of the argument array (Element 0 and 1). Element 1 of the...
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a function that takes a list of integers as input and returns a list with...
Write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2] Do not use any special or built in functions like append, reverse etc.
C++ The minimum function. (a) Write a function that takes two integers and returns the value...
C++ The minimum function. (a) Write a function that takes two integers and returns the value of the smaller one. In the main() function provide 5 test cases to verify its correctness. (b) Write the function that takes two characters and return the smaller one in the lexicographical order. Write the main() function that tests that functions for 5 different pairs of character type variables. (c) Write a generic function that takes two numeric objects and returns the value of...
Write a function file that accepts each of the four vectors as inputs. The function file...
Write a function file that accepts each of the four vectors as inputs. The function file should plot the data on different graphs in the same window. You need to add axis labels and graph titles. time- 0 5 10 15 20 25 30 A1- 0 7 11 19 15 14 7 A2- 0 10 15 21 16 11 13 A3- 0 9 13 17 22 25 21
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT