Answer to Question #255100 in C++ for Prince Ariel Borce

Question #255100
Write a C++ program to calculate the sum of the numbers from 300 to 600. The formula for calculating this sum is sum = (n / 2) × (2 × a + (n - 1) × d), where n = number of terms to be added, a = the first number, and d = the difference between each number and the next number (d = 1)
1
Expert's answer
2021-10-22T07:39:44-0400
#include <iostream>

using namespace std;

int main() {
  // sum(1..n) = n * (n + 1) / 2 = (a_1 + a_n) * n / 2 
  cout << (300 + 600) * 301 / 2 << endl;
  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