Question

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 + k;

      cout << sum;

Answer:

for (int k = 2; k < 5; k++)                

   {

      for (int j = 3; j < 6; j++)

      cout << setw(4) << (k + j) << " ";

      cout << endl;

   }

    Answer:

int sum = 0;                              

    int a = 6;

    while(a < 9)

    {

      for (int k = a; k < 8; k++)

        sum = sum + k;

      a = a + 1;

     }

     

    cout << sum << endl;

     Answer:

int k = 0;

for (k = 4; k < 1; k++)                     

   {

     for (int counter = 1; counter <=10; counter++)

       cout << setw(5) << counter;

     cout << endl;

   }

    cout << k << endl;

         Answer:

6. int k = 0;

   for (k = 1; k <= 10; k++)                   

   {

     for (int counter = 1; counter <= 10; counter--)

        cout << counter << endl;

     cout << " " << endl;

   }

    cout << k << endl;

Answer:

Assuming all variables have been properly declared and all source code has been properly setup in a compiler, what is the output from each of the following fragments of C++ code? Record the output after the “Answer” prompt at the end of each program fragment. (2 points each)

                

a. int answer = 5;

   int number = 8;

   number = number + ++answer;

   cout << answer << " " << number;

          

    

              

//Answer:

b. int answer = 5;

   int number = 8;

   number = number + answer--;

   cout << answer << " " << number;

              

         

   //Answer:

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

1. for (int j = 25; j > 16; j -= 3)

       cout << setw(5) << j;

    Answer: 25 22 19

Explanation

Prints number in the width of 5

2. int sum = 0;

      for (int k = -2; k <= 2; k++)

        sum = sum + k;

      cout << sum;

Answer: 0

Explanation

-2 -1 + 0 + 1 + 2 = 0

for (int k = 2; k < 5; k++)                

   {

      for (int j = 3; j < 6; j++)

      cout << setw(4) << (k + j) << " ";

      cout << endl;

   }

Answer:

int sum = 0;                              

    int a = 6;

    while(a < 9)

    {

      for (int k = a; k < 8; k++)

        sum = sum + k;

      a = a + 1;

     }

     

    cout << sum << endl;

Answer: 20

// Note: 4 sub parts at a time please -- Policy of Chegg

Add a comment
Know the answer?
Add Answer to:
What is the output from each of the following segments of C++ code? Record the output...
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
  • 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.) for (int k = 2; k < 5; k++)                    {       for (int j = 3; j < 6; j++)      cout << setw(4) << (k + j) << " ";       cout << endl;    }

  • A. What is the output of the following C++ code fragment? (all variables are of type...

    A. What is the output of the following C++ code fragment? (all variables are of type int) int count-1; int y-100; while (count 3) y=y-1 ; count+t cout << y << endl; cout<< count <<endl What is the value of x after control leaves the following while loop? (all variables are of type int) B. int x0 while (x < 20) sum- sum+x cout << sum<< endl;

  • points): Show the output of the code below as it would appear on the monitor. int...

    points): Show the output of the code below as it would appear on the monitor. int main cout <<" <<endl: int wildcat 2: while (wildcat > 5) cout << wildcat <<endl; wildcat++ cout <K*<< endl; int jayhavk 5i do cout << jayhawk <s endl: while (jayhawk0) cout <<*" << endl; int wolverine l: while (wolverine 0 &&wolverine < 10) cout << wolverine <<endl: wolverine2: cout <<" <<endl: for (int zag-4; zag>0; zag_) cout <<****" << endl; for (int i-10; i<-30;...

  • 2. What is the output of the following code fragment? n = 1; while (n <=...

    2. What is the output of the following code fragment? n = 1; while (n <= 5) { n++; cout << n << ' '; a.1 2 3 4 5 b. 1 2 3 4 c. 1 1 1 forever d. 2 3 4 5 e. 2 3 4 5 6 3. What is the termination condition for the following While loop? while (beta > 0 && beta < 10) { cout << beta << endl; cin >> beta; }...

  • 3) What are the final values of a, b, c in the following code fragment (1.5...

    3) What are the final values of a, b, c in the following code fragment (1.5 point): int a = 6 , b = 127 , c; c = ( ++a ) + ( b -- ); Answer: 4) What are the final values of a, b, c in the following code fragment (1.5 point): int a = 6 , b = 127 , c; c = (a++) + ( -- b); Answer: 5) What is displayed by this poorly...

  • 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;...

  • 12. What is the output of the following C++ code? int x; int y; int *p...

    12. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; *p = 35; *q = 98; *p = *q; cout << x << " " << y << endl; cout << *p << " " << *q << endl; 13. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; x = 35; y = 46; p...

  • Need done in C++ Can not get my code to properly display output. Instructions below. The...

    Need done in C++ Can not get my code to properly display output. Instructions below. The code compiles but output is very off. Write a program that scores the following data about a soccer player in a structure:            Player’s Name            Player’s Number            Points Scored by Player      The program should keep an array of 12 of these structures. Each element is for a different player on a team. When the program runs, it should ask the user...

  • What are the errors in the following code? My professor gave us this prewritten code and...

    What are the errors in the following code? My professor gave us this prewritten code and asked us to find the errors in it so that it can run properly #include <cstdlib> #include <ctime> #include <iostream> using namespace std; // input: integer // output: none // adds five to the given parameter void addFive( int x ) { x += 5; } // input: none // output: a random number int generateRandomNumber() { srand( time(0) ); return rand() % 100;...

  • Consider the following code segment, what is the output? //you please explain your answer with all...

    Consider the following code segment, what is the output? //you please explain your answer with all the steps?? int j, k; for (k=0;k<10; k++) { for (j=0; j<5;j++) cout << "*"; } cout << endl;

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