fork download
#include 
#include 
#include 
#include 

std::vector > sums(int array[], int size)
{
        std::vector > result(size - 1);
        //build the two element sums
        for(int *p = array; p - array < size - 1; ++p)
                result[0].push_back(std::accumulate(p, p + 2, 0));
        //build the rest of the sums
        for(int i = 1; i < size - 1; ++i)
                for(int j = 0; j < size - (i + 1); ++j)
                        result[i].push_back(result[i - 1][j] + array[i + j + 1]);
        return result;
}

int main()
{
        int array[] = {1, 2, 3, 4, 5};
        for(int i = 0; i < sizeof(array)/sizeof(*array); ++i)
        {
                std::cout << std::setw(3) << array[i];
        }
        std::cout << std::endl;
        std::vector > v = sums(array, sizeof(array)/sizeof(*array));
        for(int i = 0; i < v.size(); ++i)
        {
                for(int j = 0; j < v[i].size(); ++j)
                        std::cout << std::setw(3) << v[i][j];
                std::cout << std::endl;
        }
}
Success #stdin #stdout 0.02s 2860KB
stdin
Standard input is empty
stdout
  1  2  3  4  5
  3  5  7  9
  6  9 12
 10 14
 15