Create a vector of 100 integers PRG from 1 to 500. Find the max and min and print those out. Please use c++.
PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE
#include <iostream>
#include <vector>
#include <time.h>
using namespace std;
int main(int argc, char const *argv[])
{
srand (time(NULL));
vector<int> v;
for(int i=0;i<100;i++){
int c = rand() % 500 + 1;
v.push_back(c);
}
int max = v[0];
int min = v[0];
for(int i=0;i<100;i++){
if(max<v[i])
max=v[i];
if(min>v[i])
min=v[i];
}
cout<<"Max: "<<max<<endl;
cout<<"Min: "<<min<<endl;
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.