Thursday, October 26, 2017

C++ Code Review: calculates sum of series of type x+x^2/2+x^3/3+...+x^n

 

Description: This program calculates sum of series of type x+x^2/2+x^3/3+...+x^n.

Code:

//Compiling Tool: Code::Block IDE with MinGW

//Program calculates sum of series of type x+x^2/2+x^3/3+...+x^n.

 

#include<iostream>

#include<conio.h> //for getch()

#include<math.h> // for pow()

 

using namespace std;

 

int main()

{

 

    int i,n;

    float x,sum=0;

 

    cout<<"Series Type:x+x^2/2+x^3/3+...+x^n"<<endl;

    cout<<"Enter the value of x and n:";

    cin>>x>>n;

 

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

        sum+=pow(x,i)/i;

    cout<<"Sum="<<sum;

    getch();

}  

 Output:

 clip_image002

If you want to write or construct or program C++ mini-project and do not know how or from where to start buy this simple e-book: Code Review of 26 C++ mini-projects. For book sample click this link.

Add your comments in below available comment box.

Note: Click these label/tags to view all related posts. Tags: C++Code

 

…till next post, bye-bye & take care.

No comments:

Post a Comment