Question #19071

write a program to print the sum of the following series : 1+16+49+100+169

Expert's answer

#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();

}

#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();

}

## Comments

## Leave a comment