Answer to Question #255724 in C++ for motje

Question #255724

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


1
Expert's answer
2021-10-23T23:30:42-0400
#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;
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS