What will be the output of the following C++ code? [code] #include <iostream> #include <algorithm> #include <vector> #include

Nguyên Lê

New member
What will be the output of the following C++ code?
Code:
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <functional>
    using namespace std;
    int op_increase (int i)
    {
        return ++i;
    }
    int main ()
    {
        vector<int> a;
        vector<int> b;
        for (int i = 1; i < 4; i++)
        a.push_back (i * 10);
        b.resize(a.size());
        transform (a.begin(), a.end(), b.begin(), op_increase);
        transform (a.begin(), a.end(), b.begin(), a.begin(), plus<int>());
        for (vector<int> :: iterator it = a.begin(); it != a.end(); ++it)
            cout << ' ' << *it;
        return 0;
    }
A. 21
B. 41
C. 61
D. 21 41 61
 

Tìm kiếm

Back
Top