agment: int x = 20, p = 1, n; while (x >= 5){ n = 5; while (n <= x){ p += n; n++; } x = x - 3; } Which of the following C++ code fragments is equivalent to the above code? 2. int x, p = 1, n; for(x = 20; x>= 5; x = x- 3) for(n = 5 ; n<= x ; n ++) 1. int x, p = 1, n; for (x = 20 ; x>= 5; n= 5) for (x = x - 3;n<= x ;n++ ) p+= n; 3. int x, p = 1, n; for(x = 20; x>=5; x = x - 3) for(n ++; n<= x; n= 5) p+= n; p+= n; 4. int x, p = 1, n; for(x = 20; x >= 5 ;x = x - 3) for(n = 5 ; n<=x ; p+= n ) n ++; 1. code 1 b. code 3 c. code 4 d. code 2

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.5: A Closer Look: Loop Programming Techniques
Problem 12E: (Program) Write a program that tests the effectiveness of the rand() library function. Start by...
icon
Related questions
Question
Consider the following C++ code fragment:
int x = 20, p = 1, n;
while (x >= 5){
n = 5;
while (n <= x){
p += n;
n++;
}
x = x - 3;
}
Which of the following C++ code fragments is equivalent to the above code?
2. int x, p = 1, n;
for(x = 20; x>= 5; x = x - 3)
for(n = 5 ; n<<= x;n ++)
p+= n;
1. int x, p = 1, n;
for (x = 20 ; x >= 5; n = 5)
for (x = x - 3;n<= x ;n++ )
p += n;
3. int x, p = 1, n;
for(x = 20; x >=5; x = x - 3)
for(n ++; n<= x; n= 5)
p += n;
4. int x, p = 1, n;
for(x = 20; x>= 5 ;x = x - 3)
for(n = 5 ; n<= x ; p+= n )
n ++;
a. code 1
b. code 3
C. code 4
d. code 2
Transcribed Image Text:Consider the following C++ code fragment: int x = 20, p = 1, n; while (x >= 5){ n = 5; while (n <= x){ p += n; n++; } x = x - 3; } Which of the following C++ code fragments is equivalent to the above code? 2. int x, p = 1, n; for(x = 20; x>= 5; x = x - 3) for(n = 5 ; n<<= x;n ++) p+= n; 1. int x, p = 1, n; for (x = 20 ; x >= 5; n = 5) for (x = x - 3;n<= x ;n++ ) p += n; 3. int x, p = 1, n; for(x = 20; x >=5; x = x - 3) for(n ++; n<= x; n= 5) p += n; 4. int x, p = 1, n; for(x = 20; x>= 5 ;x = x - 3) for(n = 5 ; n<= x ; p+= n ) n ++; a. code 1 b. code 3 C. code 4 d. code 2
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
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++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr