write a program to find the smallest value in a vector that is larger than the smallest vaue presented. for example 1 ,2 , -7 . -6 . 3 smallest = -5 . another example -45 , -1000 , -1 , -2 , smallest is -999
#include<iostream>
#include<vector>
using namespace std;
int main(){
vector<int>vect;
vect.push_back(1);
vect.push_back(2);
vect.push_back(-7);
vect.push_back(-6);
vect.push_back(3);
auto min = vect[0];
int index = 0;
for(auto i=0; i<vect.size(); i++){
if(vect[i]<min){
min = vect[i];
}
}
cout<<min-1<<endl;
}
Comments
Leave a comment