20. Program to calculate and display the sum of the following series using for loop: 1 + 2x + 3x^2 + 4x^3 + 5x^4

Chapter 6: 

Looping Structures

Programming Exercise

Problem # 20:

Write a program to calculate and display the sum of the following series using for loop:
1 + 2x + 3x^2 + 4x^3 + 5x^4

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
#include<math.h>
int main()
{
    int x, n=1, num, sum=0;
    cout<<"Enter the value of x:";
    cin>>x;
    for(num=0;num<=4;num++)
    {
        sum=sum+(n*pow(x,num));
        n++;
    }
    cout<<"\nSum of the series is:"<<sum;  
    return 0;  
}

Let me know in the comment section if you have any question.

Previous Post:
19. Program to calculate and display sum of the following series using for loop: 1! + 2! + 3! + 4! + 5!

Comments