answersLogoWhite

0

How do you add n numbers by using c plus plus?

Updated: 8/20/2019
User Avatar

Wiki User

10y ago

Best Answer

If you're reading the numbers sequentially, keep a running total. Alternatively, pass all the numbers to a function using a variable-length argument. Alternatively push the numbers into a vector then sum the vector with the following function:

void sum_vector(std::vector<int> a)

{

int total=0;

for(int i=0; i<a.size(); ++i)

total+=a[i];

return(total);

}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you add n numbers by using c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you add more than two numbers in C plus plus?

sum = a + b + c;


How do you add 3 numbers using c plus plus?

int x = 1, y = 2, z = 3; int f = x + y + z;


How do you alternate the input numbers using for loop in c plus plus?

Input a variable.


Add two numbers in pointer in using c plus plus?

int* a = new int(40); int* b = new int(2); int x = *a + *b; // x = 42 delete b; delete a;


Write a c program to add 2 no without using plus operator?

You can make use of pointers to achieve this.void add( int *a, int *b){(*a) += (*b);}Now if two numbers a and b are given and you need to store the value in variable c, then you would perform:c = a;add(&c,&b);


How a program in c that will add 2 numbers without using any plus operator?

int main() { int a=10,b=20; while(a--) b++; printf("%d",b); } or: a -= -b;


What is the sum of complex numbers?

In (a+bi) + (c+di), you add the real parts using the laws for real numbers and do the same for the imanginary parts. (a+c)+(b+d)i


Write a c plus plus program to find the largest among three numbers using ternary operators?

R = (A &gt; B &amp;&amp; A &gt; C) ? A : (B &gt; C) ? B : C; // parentheses not necessary - for clarity only


How many bytes are there for a plus b plus c?

It completely depends the datatype that you have assigned for the variables 'a' , 'b' , and 'c'. Check the compiler that you are using for the size of the datatype in bytes. Add them and thus you will get the answer.


Can you add two irrational numbers that are not conjugates of one another ie a plus b and a minus b to get a rational number?

You can also have any numbers like (a + c) and (b - c), where "c" is the irrational part, and "a" and "b" are rational.


How do you add two numbers with out using operator in c language?

Not possible. Of course you can call a function which does the addition for you, but function-calling is also an operator in C.


How do we add the C plus plus category in Netbeans?

To use C++ in Netbeans you will need a C++ compiler.