Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Practice Program 3 User will enter a value (N) which represents the number of va

ID: 3754053 • Letter: P

Question

Practice Program 3 User will enter a value (N) which represents the number of values to process (must be500) User enters N numbers in the range of -2147483648 to 2147483647* User will enter N numbers which will be stored in an array Program will compute and display the sum, average, largest, and smallest of the N numbers Program will also search the array for a specific value, NOTE you must have a separate loop to input the data+ a separate loop to sum the data and find the largest and smallest values- A separate loop is needed to search the array for a specific value #include // required header file for input/output using namespace std, nt maiI t // declare a long array that has 500 elements and other variables required for this program do// program will execute the code in the loop at least one time f" // tell the user to input a number which is the number of data values to process // write a loop to input the data into an array- only enter data in this loop // write a loop to compute the sum, largest and smallest value // display results of sum, average, largest and smallest // ask user to enter a search valuev // write a loop to search the array for the search value entered by the user // if value is found in the array display subscript number (1st occurrence) or display a message the search // value was not found in the array cout«c" to run the program again enter a 1; to stop the program enter a 0 ,,:- cin>>again, ) while (again !0); // pause the program to see the results //system("pause"); //this is a windows command; leave this statement in the code //return 0; //optional statement, may be required for .NET compiler

Explanation / Answer


#include <iostream>
#include<conio.h>
using namespace std;

int main()
{
int again=1;
int ar[500];
int size,max,min,sum,avg,search;

do
{
//loop for input
cout<<"enter size of array"<<endl;
cin>>size;
cout<<"Now Enter Elements"<<endl;
for(int i=0;i<size;i++)
{
cin>>ar[i];

}
sum=0;
min=ar[0];
max=ar[0];
for(int i=0;i<size;i++)
{
sum+=ar[i];
if(ar[i]<min)
{
min=ar[i];
}
if(ar[i]>max)
{
max=ar[i];
}
}
avg=sum/size;

cout<<"sum "<<sum<<" largest value "<<max<<" smallest value "<<min<<" average "<<avg<<endl;
cout<<"enter search element"<<endl;
cin>>search;
int flag=-1;
for(int i=0;i<size;i++)
{
if(ar[i]==search)
{
flag=i;
break;
}
}
if(flag!=-1)
{
cout<<" element found at index "<< flag<<endl;
}
else
{
cout<<"elemet not found "<<endl;
}

cout<<" to run program enter a 1 :to stop the program enter 0"<<endl;
cin>>again;

}while(again!=0);


  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote