Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,890 questions

51,821 answers

573 users

How to check there are negative elements in a specific range in an array with C++

1 Answer

0 votes
#include <iostream>     
#include <algorithm>    
 
int main () {
    std::array<int, 9> arr = {3, 4, 8, -1, 9, 2, -7, 6, 0};
 
    for (auto it = arr.begin() + 2; it != arr.end() - 3; it++) {
        std::cout << *it << ' ';
    }   
     
    if (std::any_of(arr.begin() + 2, arr.end() - 3, [](int n){return n < 0;}))
        std::cout << "\nyes";
    else
        std::cout << "\nno";
 
    return 0;
}
 
 
 
  
/*
run:
        
8 -1 9 2 
yes
        
*/

 



answered Dec 3, 2021 by avibootz
edited Dec 3, 2021 by avibootz

Related questions

...