Question

Iteration statements. Consider the following for statement in C++. What is printed at each execution of...

Iteration statements. Consider the following for statement in C++. What is printed at each execution of the loop?

int sum1 = 0, total = 0;

double sum2 = 0;

for (sum1 = 0, sum 2 = 1.0;

   sum1 < 5 && sum 2 <= 25.0;

   sum2 /= 5)

   total = ++sum1 + sum2;

   cout << “ total is “ << total << endl;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

value of total through each iteration is 2, 2, 3, 4, 5

so, it prints 5 after the loop exits

Output:


total is 5

\;\;

Add a comment
Know the answer?
Add Answer to:
Iteration statements. Consider the following for statement in C++. What is printed at each execution of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++ Consider the following statement string str "Now is the time for the party!" What is...

    c++ Consider the following statement string str "Now is the time for the party!" What is the output of the following statements? (Assume that all parts are independent of each other.) a. cout <str·size ( ) end 1 ; b. Cout << str. substr (7, 8) <<endl: c. string: :size type indstr.find'£') string s str. substr (ind 4, 9); d. cout << str insert (11,"best " <<endl e. str.erase (16, 14) str.insert (16, "to study for the exam? ") cout...

  • I need help finding the several errors and several loop errors for I get the final...

    I need help finding the several errors and several loop errors for I get the final output. C++ cLion #include <iostream> using namespace std; int main() { cout << "Welcome to Loop World" << endl; cout << endl; cout << "******************" << endl; cout << "Section I" << endl; cout << "******************" << endl; int sum; // Accumulates the total int i; // Used as loop control variable int numIter; // The number of times to iterate cout << "Enter...

  • c++ Consider the following array definition: int values[5] = {4,7,6,8,2}; What does each of the following...

    c++ Consider the following array definition: int values[5] = {4,7,6,8,2}; What does each of the following statements display? cout << values[4] << endl; cout< < (values[2] + values[3])<<endl; cout << ++values[1] << endl; marks is an integer array with 20 elements. Write a for loop that prints each element of the array. The arrays numberArray 1 and numberArray2 have 100 elements. Write code that copies the values in numberArrayl to numberArray2.

  • Examine each of the following program segments carefully. Determine what is printed from each program. There...

    Examine each of the following program segments carefully. Determine what is printed from each program. There are no intentional errors. 1. int array[] = {1, 2, 3, 4, 5}; for (int i = 0; i < 5; i++) cout << array[i]*5 << “ “; Output _________________________________ 2. int *iptr; iptr = new int[5]; for (int count = 0; count < 5; count++) iptr[count] = count+1; cout << *iptr << endl; Output _________________________________ 3. int x = 50, y = 60,...

  • MICROSOFT VISUAL STUDIO C++: 13. What will be printed when the following statements are executed? int...

    MICROSOFT VISUAL STUDIO C++: 13. What will be printed when the following statements are executed? int x = 0, y = 0; do { if(x == y) x= x + 1; else y=y — 1; } while (x<y + 4); cout << “y=“ <<y <<“ X=" << x << endl;

  • What is the output from each of the following segments of C++ code? Record the output...

    What is the output from each of the following segments of C++ code? Record the output after the “Answer” prompt at the end of each program fragment. Assume all variables have been suitably declared. (Each problem is worth 3 points.) 1. for (int j = 25; j > 16; j -= 3)        cout << setw(5) << j;     Answer: 2. int sum = 0;       for (int k = -2; k <= 2; k++)         sum = sum +...

  • Class: C++ Final Exam Dates Multiple Choice Identify the choice thar best completes the statement or...

    Class: C++ Final Exam Dates Multiple Choice Identify the choice thar best completes the statement or answer the question N 1. In s tructures, the computer repeats particular statements a certain number of times depending on some condition(s) a. looping C. selection b. branching d. sequence 2. What is the output of the following CH code? count = 1; num - 25; while (count < 25) numnum - 1: count++; cout << count << " " << num << endl;...

  • Consider the following program: # include <iostream> using namesapce std; void Func(int a, int bl double...

    Consider the following program: # include <iostream> using namesapce std; void Func(int a, int bl double number-25.0: int main) f int x-18, y-20; cout<c"Before: x- kex<" and y-eyecendl; Fundxy 1// end of main void Funcfint a, int b) int sum a+b; a-200; b-300; numberanumber+1.0 Which of the statements below are correct? (Select only the correct answers. There may be more than one) D A The statement double number-25.0; declares a global variable number B. The variables x and y are...

  • in c++ language 1.Re-write the following for loop statement by using a while loop statement: int...

    in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){                 sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() {    int score, highest;             //missing portion of the program             return 0;    } 1(c). Find the missing portion of the following code, so the...

  • Id: 40100885 in c++ output text please thanks! what is the output values printed by the...

    Id: 40100885 in c++ output text please thanks! what is the output values printed by the following code? You need to explain step by step how each printed value is calculated. #include <iostream> using namespace std; int m = 0; void SampleMethod (int); int SampleMethod(); void increase(); int main() { int j = 9; SampleMethod(j); cout << j<<endl; return 0; w Y == void SampleMethod(int i) { if (j%2 1) cout << SampleMethod() <<endl; else cout << j << "...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT