Question

3. (Desk check) a. For the following program, determine the total number of items displayed as well as the first and last numbers printed #include <iostream> using namespace std; int main( int num o; while (num <20) num++: cout <num < return 0; 248 Repetition Statements b. Enter and run the program in Exercise 3a to verify your answers to the exercise. c. How would the output be affected if the two statements in the compound statement were reversed (that is, if the cout statement came before the ++n statement)?

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

Number of iteems:

Number of items displayed based on the number of times particular loop runs.

Here loop runs from 0 to 20 that is for 0,1,2,3,..........18,19,20.

Total number of items displayed is 21.

int num=0; // initially num is 0

while(0<=20) // true  

num++; // num value is 1

cout<<num<<" "; // print 1

int num=1;

while(1<=20) // true  

num++; // num value is 2

cout<<num<<" "; // print 2

Loop : 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

outputs : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

First number printed is 1.

Last number printed is 21.

Add a comment
Know the answer?
Add Answer to:
3. (Desk check) a. For the following program, determine the total number of items displayed as...
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
  • Bly language program that c l orresponds to the following Cr+ program.Include the memory addr Wri...

    bly language program that c l orresponds to the following Cr+ program.Include the memory addr Write a Pep/9 a include <iostream> using namespace std; int num; int main ( cout << "Enter a number:" cin >> num ; num = num * 4; cout << "num 4-<< num << endl; return 0 bly language program that c l orresponds to the following Cr+ program.Include the memory addr Write a Pep/9 a include using namespace std; int num; int main (...

  • C++ Type in the above program . Before running the program, change each of the question...

    C++ Type in the above program . Before running the program, change each of the question marks to the numbers 1 through 5 indicating the order in which that line will be executed. Run the program and check your numbers. Fix and rerun if necessary. Submit the program and the output. #include <iostream> using namespace std; //prototypes void DemonstrateProc1(); void DemonstrateProc2(int num); int main() { cout << "?. Execution starts with main. " << endl; DemonstrateProc1();       cout << "?....

  • Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout...

    Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;

  • Help with C++ reverse program with leading zeros. I need to put the line from the...

    Help with C++ reverse program with leading zeros. I need to put the line from the function that display the zeros in main not in the function. So how can I move the display with leading zeros in main. Thanks. Here is my code. #include <iostream> #include <cstdlib> #include <iostream> using std::cout; using std::cin; using std::endl; //function templates int reverseNum(int); int main() { //variables char buf[100]; int num; while (true) { //prompt user for input cout << "Enter the number...

  • Write the missing statements for the following program. #include <iostream> using namespace std; int main(void) {...

    Write the missing statements for the following program. #include <iostream> using namespace std; int main(void) { int Num1; cout << "Enter 2 numbers: ";    cin >> Num2; if (Num1 < Num2) cout << "Smallest number is " << Num1; else cout << "Smallest number is " << Num2;    return 0; }

  • In PEP8 code. assembly pep8 code. 30. Write an assembly language program that corresponds to the...

    In PEP8 code. assembly pep8 code. 30. Write an assembly language program that corresponds to the following C+ program #include <iostream> using namespace std; int num; int main() cin >> num: num = num/ 16; cout << "num = " << num << endl; return 0; 21 de

  • 4. (10 pts) Show the output of the following program: (list the program outputs in the...

    4. (10 pts) Show the output of the following program: (list the program outputs in the order as they would appear on screen) #include <iostream> using namespace std; int Mystery(int); int main() int x=2, y: y=Mystery(x - 1)+1; cout << "x="«x«", y="«y < endl; y=Mystery( 2 *x); cout << "x="«x«", y="«y < endl; return 0; int Mystery (int num) int y=5; // This is a regular local variable, not a static local variable int result; y=y+num; cout << "y=" <y<",...

  • CAN YU HELP ME CONSTRUCT A FLOW CHART FOR THE FOLLOW PROGRAM ? C++ CODE: #include<iostream>...

    CAN YU HELP ME CONSTRUCT A FLOW CHART FOR THE FOLLOW PROGRAM ? C++ CODE: #include<iostream> using namespace std; int main() { //declaring variable num int num; //prompting user to enter a number cout<<"Input a number to check prime or not:"; //reading input from user cin>>num; //loop to check user input for positive number while(num<0) { cout<<"Error! Positive Integers Only.\n"; cout<<"Input a number to check prime or not:"; cin>>num; } //initializing isPrime variable with false bool isPrime = true; //loop...

  • So Im here and im stuck. I need to figure out how to get the character...

    So Im here and im stuck. I need to figure out how to get the character of the first name to be printed on a separate line and the middle and last. is there a way where i can tell a my function to stop once it hit " "? Please help. I #include iostream 2 #include string using namespace i; string name 7 getline cin, name 4 int main ) cout<"Please enter your full name: " problem3.cpp 3Write a...

  • 1.Write an assembly language program that corresponds to the following C++ program: #include <iostream> using namespace...

    1.Write an assembly language program that corresponds to the following C++ program: #include <iostream> using namespace std; const int amount = 20000; int num; int sum; int main () { cin >> num; sum = numb + amount; cout << "sum = " ,<< sum << endl; return 0; } 2. Test the program in the previous question twice. The first time, enter a value for num to make the sum within the allowed range for the Pep/8 computer. The...

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