Consider the following code fragment.   What is the output for each of the following input values for n?  (Execute the code segment 5 times and be sure to show all output as it would appear on the screen.)                                                                                                                                                            int n, a = 1, b = 2, c = 3, d = 4;                               a)    n is input as 7: cin >> n; if (n = = 3)                                                             b)      n is input as 3:     a = a + 1; else if (n = = 7)                                                      c)     n is input as 10:     b = b + 1; else if (n = = 10)                                                    d)     n is input as -1:     c = c + 1;                                                                 else                                                                       e)       n is input as 2:                                                    d = d + 1; cout << a << "   " << b << "   "  << c  << "   "  << d << endl;

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 34SA
icon
Related questions
icon
Concept explainers
Question

Consider the following code fragment.   What is the output for each of the following input values for n?  (Execute the code segment 5 times and be sure to show all output as it would appear on the screen.)                                                                                                                                                           

int n, a = 1, b = 2, c = 3, d = 4;                               a)    n is input as 7:

cin >> n;

if (n = = 3)                                                             b)      n is input as 3:

    a = a + 1;

else if (n = = 7)                                                      c)     n is input as 10:

    b = b + 1;

else if (n = = 10)                                                    d)     n is input as -1:

    c = c + 1;                                                                

else                                                                       e)       n is input as 2:                                                

   d = d + 1;

cout << a << "   " << b << "   "  << c  << "   "  << d << endl;

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 5 images

Blurred answer
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning