Home » C++ Programming » Functions » Question
  1. What is the output of this program?
      #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    int main ()
    {
    int num[] = {15, 25, 35, 35, 25, 15, 15, 25};
    vector<int> VectorData(num, num + 8);
    sort (VectorData.begin(), VectorData.end());
    vector<int> :: iterator Lower, Upper;
    Lower = lower_bound (VectorData.begin(), VectorData.end(), 35);
    Upper = upper_bound (VectorData.begin(), VectorData.end(), 35);
    cout << (Lower - VectorData.begin()) << ' ';
    cout << (Upper - VectorData.begin()) << '\n';
    return 0;
    }
    1. 15 25
    2. 25 15
    3. 6 8
    4. 8 6
    5. Compilation Error
Correct Option: C

In this program, We are finding the upper bound and lower bound values by using lower_bound and upper_bound methods.



Your comments will be displayed only after manual approval.