Write a program that generates an array of 10 elements filled up with random int
ID: 2292459 • Letter: W
Question
Write a program that generates an array of 10 elements filled up with random integer number ranging from 50 to 150, and display on the screen.
After the creation and displaying of the array, the program displays the following:
[A]verage [E]ven [M]inimum [Q]uit
please select an option:_
Then, if the user selects:
A (lowercase or uppercase): the program displays the mean value of the numbers contained in the array (2 decimal digits maximum).
E (lowercase or uppercase): The program displays only the even numbers (not indexes) of the array.
M (lowercase or uppercase): the program displays the minimum present in the array.
Q (lowercase or uppercase): the program exits.
Can you actually run and build the program and show the same output as the one above it? I appreciate it.
he randon generated array is: 98 128 78 79 85 118 1)a 189 182 62 Elven eleet an optiont he averagealue of the array 97.38 he randon generated array : 139 2 123 2 11? 53 S4 S2 89 eleet an optiont Elven QluielExplanation / Answer
code in C++
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int arr[10],i,min,sum;
char ch;
memset(arr,0,sizeof(arr));
for(i=0;i<10;i++)
{
arr[i]= rand()%101 + 50;
cout<<arr[i]<<endl;
}
cout<<"enter your choice A/a , E/e , M/m , Q/q"<<endl;
cin>>ch;
sum =0;
float avg ;
switch(ch)
{
case 'A':
case 'a' : for(i=0;i<10;i++)
sum+=arr[i];
avg = sum/10.0;
cout<<avg<<endl;
break;
case 'e':
case 'E': for(i=0;i<10;i++)
{
if(arr[i]%2==0)
cout<<arr[i]<<" ";
}
break;
case 'M':
case 'm': min = arr[0];
for(i=1;i<10;i++)
{
if(arr[i]< min)
min =arr[i];
}
cout<<min<<endl;
break;
case 'q':
case 'Q':
break;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.