> For the complete documentation index, see [llms.txt](https://abhyas-kanaujia.gitbook.io/lb-dsa-notes-and-homework-abhyas/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://abhyas-kanaujia.gitbook.io/lb-dsa-notes-and-homework-abhyas/03-programming-basics-ii/homework/04.-sum-of-n-integers-using-loop.md).

# 04. Sum of n integers using loop

```
Input: n
Result = 1 + 2 + 3 + ... + n
Output: result
```

```cpp
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int n;
  cout << "n: ";
  cin >> n;

  int res = 0;
  for (int i = 1; i <= n; i++)
    res += i;

  cout << res;
  return 0;
}
```
