0
how to find the next( bigger than the number i have given as input) bigger num?
vector<int>v={23,68,2,5,8}; // suppose : I give 7 as input //output should be: 8 what would be the code for that?
5 Respostas
+ 2
You can sort the vector and use std::find_if():
int range = 7;
std::sort(v.begin(),v.end());
std::cout<<*(std::find_if(v.begin(),v.end(),[range](int c){return c>range;}));
www.cplusplus.com/reference/algorithm/find_if
+ 1
i made this code for this purpose. Hope it helps you
https://code.sololearn.com/cxG1ENsGcM5O/?ref=app
0
Iterate through the vector and look for smallest number that's bigger than input.
0
loop in every item, calculate value of difference between current item and input and if result is positive store it in 'd' var... Continue in this way replacing 'd' if current result is lower (and positive) of 'd'
0
you can sort the array, then for loop and return or cout the first number > input.