Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include using namespace std; int main() { int n, total = 0; cin >> n; total = 0; while (n > 0) { total =
#include
using namespace std;
int main() {
int n, total = 0;
cin >> n;
total = 0;
while(n > 0)
{
total = total + n;
n--;
} cout
return 0;
}
I did it this way but I can't seem to get it right. I am trying to answer it with C++ "while loops. "
Create a program which will implement the sum of the numbers between 1 and n where n is an integer. When completed, the program will allow the user to input a positive integer (n) then the program will add all numbers between 1 and n (including n) and output the sum. For example, if the user enters 8 then the program will sum the numbers 1 through 8 and will output the sum. Test your program with the following inputs: a. 8 (sum is 36) b. 75 (sum is 2850) c. 100 (sum is 5050)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started