(Summing Integers) Write a program that uses a for statement to sum a sequence of inte- gers. Assume that the first integer read specifies the number of values remaining to be entered. Your program should read only one value per input statement. A typical input sequence might be 5 100 200 300 400 500 where the 5 indicates that the subsequent 5 values are to be summed.

What will be an ideal response?

```
// Total a sequence of integers.
#include
using namespace std;

int main()
{
int total = 0; // current total
int number; // number of values
int value; // current value

// display prompt
cout << "Enter the number of values to be summed "
<< "followed by the values: \n";
cin >> number; // input number of values

// loop number times
for ( int i = 1; i <= number; i++ )
{
cin >> value;
total += value;
} // end for

// display total
cout << "Sum of the " << number << " values is " << total << endl;
} // end main
```

Computer Science & Information Technology

You might also like to view...

According to James Moor, taking “the ethical point of view” means

a. abiding by your religious beliefs. b. deciding that other people and their core values are worthy of your respect. c. choosing to sacrifice your own good for the good of someone else. d. putting self-interest above the interests of everyone else. e. refusing to accept help from other people.

Computer Science & Information Technology

What would be the time complexity of the size operation for each of the implementations if there were not a count variable?

What will be an ideal response?

Computer Science & Information Technology