Write, compile, and execute a C++ program to calculate the sum of the numbers from 1 to 100. 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. Your program should produce the display
The sum of the number is xxxx.
where the xxxx represents a field width of four digits and should be replaced by the sum computer by the program.

2 Years
Discussion Span
Last Post by David W

You need to read the rules of this forum, especially the rule that reads as follows:

Do provide evidence of having done some work yourself if posting questions from school or work assignments

Don't copy-paste your homework assignments (or other exercises) and expect people to simply give out a fully working answer for it, because that is against our rules and it is against your best interest.

This warning is good for all your other threads too (1 2 3). If you persist in spamming the forum with copy-pasted exercise questions, then we'd have to give you an infraction for it and delete the posts.

What have you tried to do towards solving this problem? Please show us what code you are working on for this and ask questions specific to what prevents you from solving it?

  1    2    3    4 ....    n
  n  n-1  n-2  n-3 ....    1
n+1  n+1  n+1  n+1 ...   n+1

So ... 2 * SUM = n*(n+1)
Thus       SUM = n*(n+1)/2

Can you write code to prompt and input an integer into a variable ...
(maybe label that int variable n) ?

Show what code you can do ...
then we can see where you are at
and be able to help you from there.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.