Answer to Question #19071 in C++ for kshitij

Question #19071
write a program to print the sum of the following series : 1+16+49+100+169
1
Expert's answer
2012-11-20T10:06:11-0500
#include <iostream>
#include <conio.h>

using namespace std;

long long CalculateSum(int seriesLength)
{
long long result = 0;
int number = 1;

for (int k = 0; k < seriesLength; k++, number += 3)
& result += number * number;
return result;
}

void main()
{
int seriesLength;
cout << "Enter the length of the series: ";
cin >> seriesLength;
cout << "The sum of the series is: " << CalculateSum(seriesLength);
getch();
}

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
APPROVED BY CLIENTS