//Time Complexity of This function (n*k), Here n is size of array or vector and k is complexity of internal function
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cout << "Enter Array Size :: ";
cin >> n;
int a[n];
cout << "\nEnter Array Element :: \n";
for(int i=0;i<n;i++)
cin >> a[i];
int sum = accumulate(a, a+n, 0);
cout << "\nSummation is :: " << sum << "\n";
cout << "\nFor Vector :: \n\n";
cout << "Enter Vector Size :: ";
cin >> n;
vector<int>v(n);
cout << "\nEnter Vector Element :: \n";
for(int i=0;i<n;i++)
cin >> v[i];
sum = accumulate(v.begin(), v.end(), 0);
cout << "\nSummation is :: " << sum;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cout << "Enter Array Size :: ";
cin >> n;
int a[n];
cout << "\nEnter Array Element :: \n";
for(int i=0;i<n;i++)
cin >> a[i];
int sum = accumulate(a, a+n, 0);
cout << "\nSummation is :: " << sum << "\n";
cout << "\nFor Vector :: \n\n";
cout << "Enter Vector Size :: ";
cin >> n;
vector<int>v(n);
cout << "\nEnter Vector Element :: \n";
for(int i=0;i<n;i++)
cin >> v[i];
sum = accumulate(v.begin(), v.end(), 0);
cout << "\nSummation is :: " << sum;
return 0;
}
Comments
Post a Comment