The sum of the components in vectors.

How can I get the sum of the components that I introduce in v[i]?

1
2
3
4
5
6
  int v[9],a,b,i;
  cin>>a;
  for (i=0;i<a,++i) {
   cout<<"v["<<i+1<>v[i];
  }
  b=//how can I make the sum of the numbers that i introduced in v[i]?; 
There's an example of finding the sum of the values in an array in the tutorial, under the heading Accessing the values of an array
 
    result += foo[n];

See tutorial page:
http://www.cplusplus.com/doc/tutorial/arrays/

Once you master the material in the tutorial, then the standard library has a generic "sum" function:
http://www.cplusplus.com/reference/numeric/accumulate/
Topic archived. No new replies allowed.