Friday, June 4, 2021

program for making a series and sum of series (POP) (134)

#include <iostream>

using namespace std;


int main()

{

    int i, n;

    float s = 0.0;

    cout << " Input number of terms: ";

    cin >> n;

    for (i = 1; i <= n; i++) 

    {

        if (i < n) 

        {

            cout << "1/" << i << " + ";

            s += 1 / (float)i;

        }

        if (i == n) 

        {

            cout << "1/" << i<<endl;

            s += 1 / (float)i;

        }

    }

    cout<<"the sum is:" << s << endl;

} 

No comments:

Post a Comment