プログラミング道場 ACM/ICPC

配列の総和

最終更新:

kit

- view
だれでも歓迎! 編集

配列の総和


/*
	template<class _InIt,	class _Ty>
	_Ty accumulate(_InIt _First, _InIt _Last, _Ty _Val)

	template<class _InIt,	class _Ty, class _Fn2>
	_Ty _Accumulate(_InIt _First, _InIt _Last, _Ty _Val, _Fn2 _Func)
*/

#include <numeric>
#include <functional>
#include <iostream>

using namespace std;

int main()
{
	int a[] = {1,4,9};

	// 0+1+4+9 = 14
	cout << accumulate( a, a+3, 0 ) << endl;

	// 1*1*4*9 = 36
	cout << accumulate( a, a+3, 1, multiplies<int>() ) << endl;

	return 0;
}

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

人気記事ランキング
目安箱バナー