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;
}
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment