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

What will be the output of the following C++ code?
Code:
    #include <iostream>
    #include <functional>
    #include <numeric>
    using namespace std;
    int myfunction (int x, int y) 
    {
        return x + 2 * y;
    }
    struct myclass 
    {
        int operator()(int x, int y) 
        {
            return x + 3 * y;
        }
    } myobject;
    int main () 
    {
        int init = 100;
        int numbers[] = {10, 20, 30};
        cout << accumulate(numbers, numbers + 3, init);
        cout << endl;
    }
A. 100
B. 140
C. 160
D. 180
 

Thành Đạt

New member
Answer: c
Explanation: In this program, We are calculating the product of every number in the given range by using accumulate function.
Output:
Code:
$ g++ gnl1.cpp
$ a.out
160
 

Tìm kiếm

Top