Writing a for statement to add all multiples


Assignment:

Q1. What is the output of the following C++ code?

num = 1;
while (num < 10)
{
    cout << num << “ “;
    num = num + 2;
}
cout << endl;

Q2. Suppose that the input is 38 45 71 4 -1.  What is the output of the following code?  Assume all variables are properly declared.

cin >> sum;
cin >> num;
while (num != -1)
{
   sum = sum + num;
   cin >> num;
}
cout << “Sum = “ << sum << endl;

Q3. Write a for statement to add all the multiples of 3 between 1 and 100.

Your answer must be typed, double-spaced, Times New Roman font (size 12), one-inch margins on all sides, APA format.

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Writing a for statement to add all multiples
Reference No:- TGS01926306

Now Priced at $30 (50% Discount)

Recommended (94%)

Rated (4.6/5)