Thursday, October 12, 2017

C++ Code Review: calculates sum of series of type 1+(1+2)+(1+2+3)+...n

Description: This program calculates sum of series of type 1+(1+2)+(1+2+3)+...n.

Code:

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

//Program calculates sum of series of type 1+(1+2)+(1+2+3)+...n.

 

#include<iostream>

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

 

using namespace std;

 

int main()

{

 

    int n;

    cout<<"Series Type:1+(1/4)+(1/8)+(1/12)+...(1/100)"<<endl;

 

    float num=0;

    for (float i=4; i<= 100; i=i+4)

    {

        num=num+(1/i);

    }

    num=num+1;

 

    cout<<"Total of series: "<< num;

    getch();

}

 

Output:

 clip_image002

f 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