Saturday, 3 January 2015

C++ program to calculate the sum of series where n is input by user. 1 + 1/2 + 1/3 + 1/4 + 1/5 +…………1/n

#include<iostream>
using namespace std;
int main()
{
    int number;
    double sum=0;
    cout<<"Enter the Value of the maximum number : ";
    cin>>number;

    for(double i=1; i<=number; i++)
    {
        double fraction=1/i;
        sum=sum+fraction;
    }
   
    cout<<"Sum of the series : "<<sum<<endl;

    return 0;

}

No comments:

Post a Comment