|
STL의 accumulate 알고리듬을 사용한 방법입니다.
#include <iostream>
#pragma hdrstop
#include <numeric>
using namespace std;
int main()
{
int x[2], *a = &x[0], *b = &x[1];
cin >> *a >> *b;
int c = accumulate(a, b + 1, 0);
cout << c << endl;
return 0;
}
또는
#include <iostream>
#pragma hdrstop
#include <numeric>
using namespace std;
int main()
{
int x[2], &a = x[0], &b = x[1];
cin >> a >> b;
int c = accumulate(&a, &b + 1, 0);
cout << c << endl;
return 0;
}
|