[ create a new paste ] login | about

Link: http://codepad.org/klrZRDht    [ raw code | output | fork ]

mohit_at_codepad - C++, pasted on Mar 12:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <numeric>
#include <iostream>
#include <vector>
using namespace std;

typedef double mytype;
int main() {
  mytype da[] = {1, 1, 2, 5};
  vector<mytype> dv(&da[0], da + sizeof da / sizeof da[0]);
//This(↓) line is an error. <init> argument in accumulate should be double
//cout << "Sum = " << accumulate(&da[0], da + sizeof da / sizeof da[0], 0) << endl;
  cout << "Sum = " << accumulate(&da[0], da + sizeof da / sizeof da[0], 0.0) << endl;
  return 0;
}


Output:
1
Sum = 9


Create a new paste based on this one


Comments: