Question

In: Computer Science

Create a vector of 100 integers PRG from 1 to 500. Find the max and min...

Create a vector of 100 integers PRG from 1 to 500. Find the max and min and print those out. Please use c++. Please use #include<iostream>, std::min_element, and std::max_element.

Solutions

Expert Solution

Note --> We are taking 100 integers from User and if user enter a value less than 1 or greater than 500 then program exits by printing a error message

Code is

#include <bits/stdc++.h>
#include<iostream>
#include <vector>
using namespace std;
int main()
{
   vector<int> v (100);

   // Take a Loop to push 50 characters in the Vector
   cout<<"Enter 100 integers range from 1 to 500 ";
/
/ Use a loop to take 50 characters from user
for(int i = 0; i < v.size(); i++)
{
cin>>v[i];
if(v[i]<1 || v[i]>500)
{

// if entered value not in range then exit the program
cout<<"Integer value not in Range ";
exit(0);
}
}

// Find the min element
cout << "\nMin Element = "<< *min_element(v.begin(), v.end());

// Find the max element
cout << "\nMax Element = " << *max_element(v.begin(), v.end());
return 0;
}

Code Screenshot

This is how you can vector of 100 integers and find max and min out .

If u like the answer then Give it a Thumbs Up and have any doubt comment it


Related Solutions

Create a vector of 100 integers PRG from 1 to 500. Find the max and min...
Create a vector of 100 integers PRG from 1 to 500. Find the max and min and print those out. Please use c++.
Create a vector of 50 characters PRG from A to Z. Sort the list in reverse...
Create a vector of 50 characters PRG from A to Z. Sort the list in reverse order (from Z to A). Please use c++. Please use #include<iostream>. Please don't use the ASCII values.
Using c++, 1: Create a vector of 20 randomly generated integers, then 2. Create a new...
Using c++, 1: Create a vector of 20 randomly generated integers, then 2. Create a new vector that will only store the even numbers from the original vector. 3. Display the original vector and the vector of even integers to the console.
Find the absolute max and min in [-1,1] for f(x)=ln(x2+x+1)
Find the absolute max and min in [-1,1] for f(x)=ln(x2+x+1)
The charging min value is zero and max value is 100. When the charger is not...
The charging min value is zero and max value is 100. When the charger is not plugged, the robot is in discharging state and the battery decreases. When charger is attached, the state is changed to charging and the value increase. Once it reaches the max limit, the state changes to battery full. Q) Write boundary value analysis for battery level. Q) Write test cases for battery level for both valid and invalid.
Use R code to do the following!!!! 1. Create a vector v1 that will contain integers...
Use R code to do the following!!!! 1. Create a vector v1 that will contain integers from -30 to 60. 2. Copy v1 into a vector v2 and add names 'odd' or 'even' based on the value. 3. Copy v1 into a vector v3 and if the number can be divided by 3, replace it by 'NA'. 4. Assign the mean of v3 to v4 ignoring the 'NA'.
Find the absolute max/min values of f(x) = x/x2+1 on the interval [-2,2].
Find the absolute max/min values of f(x) = x/x2+1 on the interval [-2,2].
Find the number of integers between 100 and 1000 that are
Find the number of integers between 100 and 1000 that are (i) divisible by 7  (ii) not divisible by 7      
In R-Syntax, create a vector of 100 employees ("Employee 1", "Employee 2", ... "Employee 100") [Hint:...
In R-Syntax, create a vector of 100 employees ("Employee 1", "Employee 2", ... "Employee 100") [Hint: use the `paste()` function and vector recycling to add a number to the word "Employee"] then create a vector of 100 random salaries for the year 2017 [Use the `runif()` function to pick random numbers between 40000 and 50000] and finally create a vector of 100 salary adjustments between -5000 and 10000 [use runif() to pick 100 random #'s in that range]
1. Find absolute max and min of     f(x,y)= x^2- xy + y^2 +1 on the closed...
1. Find absolute max and min of     f(x,y)= x^2- xy + y^2 +1 on the closed triangular plate in the first quadrant x=0, y=4, y=x 2. Given position of a particle by π (t)= Cos2ti + 3 sin2ti,         Find the particle velocity and acceleration at t=0
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT