60 503
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #24460 in Python for Valentin

Question #24460
Write a while loop that sums the values 1 through end, inclusive. end is a variable that we define for you. So, for example, if we define end to be 6, your code should print out the result:

21
which is 1 + 2 + 3 + 4 + 5 + 6.

For problems such as these, do not include raw_input statements or define the variable end. Our automating testing will provide a value of end for you - so write your code in the following box assuming end is already defined.
Hint: Don't Use A Variable Called 'sum'
Expert's answer
#include <iostream>

#include <conio.h>
using namespace std;


int main()
{
int number=0;
cout<<"Enter number: ";
cin>>number;
int count=0;
int sum=0;
while(count<number){
count++;
sum+=count;
}
cout<<"Sum = "<<sum;
getch();
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions