Write a program that prompts the user to enter the number of elements and the nu
ID: 3634207 • Letter: W
Question
Write a program that prompts the user to enter the number of elements and the numbers themselves to be placed in an integer array that holds a maximum of 50elements. Next include a function called by main to implement the Linear search.
Add a value returning function that computes the mean of your data set.
Recall that the mean is the sum of the data values divided by the number
of pieces of data. Your program should output the size of the array
entered, the array as entered by the user, the sorted array, and the mean of the data set.
I need this program in C++
Explanation / Answer
#include<iostream>
using namespace std;
int linearsearch(int a[],int k,int num)
{
for(int i=0; i<k; i++)
if(a[i] == num)
return i;
return -1;
}
double mean(int a[],int k)
{
double men = 0;
for(int i=0; i<k; i++)
men = men + a[i];
men = men/k;
return men;
}
int main()
{
int a[50];
for(int i=0; i<50; i++)
{
cout << " enter element " << (i+1) ;
cin >> a[i];
}
cout << " mean is " << mean(a,50) << endl;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.