C++ Series : 1.5+2.5+3.5+..............+n

#include<iostream>
using namespace std;
int main()
{
    float n, i, s = 0;

    cout << "Enter A float Number : ";
    cin >> n;
    cout << endl;

    for(i=1.5;i<=n;i++)
    {
        cout << i;
        if(i != n)
        {
            cout << " + ";
        }
        s = s + i;
    }

    cout << " = " << s << endl;

    return 0;
}

Comments