In this post I will present the way to find the sum of n numbers usng for loop. Basically, we will use an array to store values and then use a variable to add values.

First of all, we need get **n **- the amount of numbers and declare an array with **n **elemets to store numbers:

```
int n;
cin >> n;
int arr[n];
```

Next, we need to get **n **numbers and use the above array to store them:

```
for (int i = 0; i < n; i++)
{
int number;
cin >> number;
arr[i] = number;
}
```

And now we need a variable, **sum**, to accumulate values of all numbers. Note that we must initialize **sum **with 0 or else it would have garbage value and lead to incorrect result.

`int sum = 0;`

Finally, we iterate through all elemets of the array add value of sum with their values:

```
for(int i = 0; i < n; i++)
{
sum = sum + arr[i];
}
cout << sum;
```

Result:

```
5
1 2 3 4 5
15
```

Here is the completed code:

```
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++)
{
int number;
cin >> number;
arr[i] = number;
}
int sum = 0;
for(int i = 0; i < n; i++)
{
sum = sum + arr[i];
}
cout << sum;
}
```

I have shown you how to calculate sum of **n **numbers. I hope that this article will help you solve similar problems.

Happy coding !