logo

Crowdly

#define main1 main /** Question C1 What is output of the program? */ //Q-stl...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

#define main1 main

/** Question C1

What is output of the program?

*/

//Q-stl-1: std::ranges::for_each; std::ranges::count; std::ranges::count_if; 

//std::ranges::all_of; std::ranges::none_of 

#include <iostream>

#include <vector>

#include <algorithm>

int main1() {

    std::vector<int> v = {-5, 6, -8, -1, -3, -9, 9, 7};

    auto it1 = std::ranges::find(v, 1);

    auto it2 = std::ranges::find_if(v, [](int x){

        return x > 0;

    });

    auto itMin = std::ranges::min_element(v);

    auto itMax = std::ranges::max_element(v);

    int p1 = (it1 == v.end()) ? -1 : static_cast<int>(it1 - v.begin());

    int p2 = (it2 == v.end()) ? -1 : static_cast<int>(it2 - v.begin());

    std::cout << p1 << "|" << p2 << "|" << *itMin << "|" << *itMax;

    return 0;

}

More questions like this

Want instant access to all verified answers on emokymai.vu.lt?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!