sum of integer in array c++
C++
// C++ program to demonstrate working of accumulate()
#include <iostream>
#include <numeric>
using namespace std;
// User defined function that returns sum of
// arr[] using accumulate() library function.
int arraySum(int a[], int n)
{
int initial_sum = 0;
return accumulate(a, a+n, initial_sum);
}
int main()
{
int a[] = {5 , 10 , 15} ;
int n = sizeof(a)/sizeof(a[0]);
cout << arraySum(a, n);
return 0;
}
// C++ program to demonstrate working of accumulate()
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
// User defined function that returns sum of
// arr[] using accumulate() library function.
int arraySum(vector<int> &v)
{
int initial_sum = 0;
return accumulate(v.begin(), v.end(), initial_sum);
}
int main()
{
vector<int> v{5 , 10 , 15} ;
cout << arraySum(v);
return 0;
}
Also in C++:
- Title
- hashing in competitive programming
- Category
- C++
- Title
- string input
- Category
- C++
- Title
- clear qlayout
- Category
- C++
- Title
- set mimetype validation in mongoose
- Category
- C++
- Title
- write to file in C++
- Category
- C++
- Title
- create a 2d array c++
- Category
- C++
- Title
- initialize array c++
- Category
- C++
- Title
- min heap declaration in c++ stl
- Category
- C++
- Title
- memcmp in cpp
- Category
- C++
- Title
- c++ how to skip the last element of vector
- Category
- C++
- Title
- C++ and endl
- Category
- C++
- Title
- to_string c++
- Category
- C++
- Title
- double to int c++
- Category
- C++
- Title
- iostream library in cpp
- Category
- C++
- Title
- struct c++
- Category
- C++
- Title
- git branch in my bash prompt
- Category
- C++
- Title
- how to find the size of a character array in c++
- Category
- C++
- Title
- switch case sinax c++
- Category
- C++
- Title
- initialize vector of vector c++
- Category
- C++
- Title
- set precision in c++
- Category
- C++
- Title
- convert char to string - c++
- Category
- C++
- Title
- error: invalid use of template-name without an argument list
- Category
- C++
- Title
- Insert into vector C++
- Category
- C++
- Title
- -> cpp
- Category
- C++
- Title
- log base 10 c+_+
- Category
- C++
- Title
- how to include seld declared header file in c++
- Category
- C++
- Title
- convert string to stream c++
- Category
- C++
- Title
- how to calculate inverse trigonometric values in c++
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- c++ argv
- Category
- C++
- Title
- c++ convert int to double
- Category
- C++
- Title
- and or in c++
- Category
- C++
- Title
- delete files c++
- Category
- C++
- Title
- c++ try
- Category
- C++
- Title
- c++ return multiple values
- Category
- C++
- Title
- c++ vector
- Category
- C++
- Title
- map vs unordered_map in C++
- Category
- C++
- Title
- set in c++
- Category
- C++
- Title
- c++ smart pointer 2d array
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- c++ function return pointer to itself
- Category
- C++
- Title
- how to use winmain function
- Category
- C++
- Title
- factorial in c++
- Category
- C++
- Title
- how to inject a dll into a game c++
- Category
- C++
- Title
- COunt the number of continous subsequences such that the sum is between
- Category
- C++
- Title
- random number in c++
- Category
- C++
- Title
- comparing strings c++
- Category
- C++
- Title
- file format not recognized treating as linker script c++
- Category
- C++
- Title
- tokenize string c++
- Category
- C++
- Title
- cpp loop through object
- Category
- C++
- Title
- font awesome bootstrap cdn
- Category
- C++
- Title
- initialise 2d vector in c++
- Category
- C++
- Title
- for loop
- Category
- C++
- Title
- how to check sqrt of number is integer c++
- Category
- C++
- Title
- memset c++
- Category
- C++
- Title
- c++ short if
- Category
- C++
- Title
- char to string c++
- Category
- C++
- Title
- how to convert n space separated integers in c++
- Category
- C++
- Title
- reference function in c++
- Category
- C++
- Title
- c++ iterate over vector
- Category
- C++
- Title
- if vector contains value c++
- Category
- C++
- Title
- how to read and write in a file c++
- Category
- C++
- Title
- how to have a queue as a parameter in c++
- Category
- C++
- Title
- how to calculate trigonometric values in c++
- Category
- C++
- Title
- counting valleys hackerrank solution in c++
- Category
- C++
- Title
- how to make an array c++
- Category
- C++
- Title
- container class in c++
- Category
- C++
- Title
- Find a element in a map C++
- Category
- C++
- Title
- initialization list c++
- Category
- C++
- Title
- c++ tutorial
- Category
- C++
- Title
- c++ over load oprator to print variable of clas
- Category
- C++
- Title
- traverse map c++
- Category
- C++
- Title
- c++ sort array of ints
- Category
- C++
- Title
- how to iterate over unordered_map c++
- Category
- C++
- Title
- simple timer arduino blynk library error
- Category
- C++
- Title
- std::substring
- Category
- C++
- Title
- c++ course
- Category
- C++
- Title
- c++ set add element
- Category
- C++
- Title
- c++ looping through a vector
- Category
- C++
- Title
- widechartomultibyte
- Category
- C++
- Title
- built in popcount c++
- Category
- C++
- Title
- queue stl c++
- Category
- C++
- Title
- min heap priority queue c++
- Category
- C++
- Title
- time function c++
- Category
- C++
- Title
- knapsack
- Category
- C++
- Title
- c++ create button
- Category
- C++
- Title
- c++ size_t
- Category
- C++
- Title
- range based for loop c++ with reference
- Category
- C++
- Title
- how to write an or in c++
- Category
- C++
- Title
- : error: ‘cont’ cannot be used as a function return (cont(cont-1))/2;
- Category
- C++
- Title
- how to check type in c++
- Category
- C++
- Title
- pbds in c++
- Category
- C++
- Title
- if not defined c++
- Category
- C++
- Title
- iterate const vector
- Category
- C++
- Title
- tuple c++
- Category
- C++
- Title
- loop through array c++
- Category
- C++
- Title
- find_if c++
- Category
- C++
- Title
- how to make a n*n 2d dynamic array in c++
- Category
- C++
- Title
- c++ program to find gcd of 3 numbers
- Category
- C++
- Title
- string to vector c++
- Category
- C++