For pair numbers

Hello ! So i got a homework in which i should make a program using "for" and it shall calculate addition of pair numbers. I can't figure it out and i tried several times. Please help me. also he gave us this formula S = 2 + 4 + ... + 2*n

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 #include <iostream>

using namespace std;

int main()
{
    int n, i, s;
    cout << "n= ";
    cin >> n;
    s = 0;
    for (i = 2; i <= 2 * n ; i = i + 2)
    {
        s = s + (2 * i);
    }
    cout << "s= " << s;
    return 0;
}
Last edited on
If you have it, please post the exact wording of your problem.Otherwise, I think your program is correct.
Topic archived. No new replies allowed.