We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
/*
* Complete the 'simpleArraySum' function below.
*
* The function is expected to return an INTEGER.
* The function accepts INTEGER_ARRAY ar as parameter.
*/
int simpleArraySum(vector ar) {
int sum{};
for(auto i : ar)
{
sum = sum + i;
}
return sum;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string ar_count_temp;
getline(cin, ar_count_temp);
int ar_count = stoi(ltrim(rtrim(ar_count_temp)));
string ar_temp_temp;
getline(cin, ar_temp_temp);
vector<string> ar_temp = split(rtrim(ar_temp_temp));
vector<int> ar(ar_count);
for (int i = 0; i < ar_count; i++) {
int ar_item = stoi(ar_temp[i]);
ar[i] = ar_item;
}
int result = simpleArraySum(ar);
fout << result << "\n";
fout.close();
return 0;
Simple Array Sum
You are viewing a single comment's thread. Return to all comments →
include
using namespace std;
string ltrim(const string &); string rtrim(const string &); vector split(const string &);
/* * Complete the 'simpleArraySum' function below. * * The function is expected to return an INTEGER. * The function accepts INTEGER_ARRAY ar as parameter. */
int simpleArraySum(vector ar) {
}
int main() { ofstream fout(getenv("OUTPUT_PATH"));
}
string ltrim(const string &str) { string s(str);
}
string rtrim(const string &str) { string s(str);
}
vector split(const string &str) { vector tokens;
}