Answer to Question #237112 in C++ for neeraj

Question #237112

Develop an OOP to find the sum of “n” terms of the following series.       

1^3 + 3 x 2^2 + 3^3 + 3 x 4^2 + 5^3 + 3 x 6^2 + . . . . . 


1
Expert's answer
2021-09-14T18:16:43-0400


#include <iostream>
#include <math.h>
using namespace std;


int main()
{
    int n;
    cout<<"\nEnter a number: ";
    cin>>n;
    int sum1=0;
    for(int i=1;i<=n;i++){
        if (i%2 !=0)
            sum1=sum1+pow(i,3);
    }
    
    int sum2=0;
    for(int i=2;i<=n;i++){
        if (i%2 ==0)
            sum2=sum2+(3*pow(i,2));
    }
    int sum=sum1+sum2;
    cout<<"\nThe sum is "<<sum;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS