Question

num = 100; while (num <= 150) num = num + 5 ; cout<< num Assume...

num = 100;

while (num <= 150)

num = num + 5 ;

cout<< num

Assume all variables are properly declared. What is the output of the C++ code above?

Answer:

A) 150

B) 155

C) 160

d) 165

0 0
Add a comment Improve this question Transcribed image text
Answer #1
num = 100;  // num is initialized to 100
while (num <= 150)
    num = num + 5;
// let's see what happens with the above for loop
// num = 100
// iteration 1, num = num+5 = 100+5 = 105
// iteration 2, num = num+5 = 105+5 = 110
// iteration 3, num = num+5 = 110+5 = 115
...
// iteration 10, num = num+5 = 145+5 = 150
// iteration 11, num = num+5 = 150+5 = 155
// now num <= 150 is false, because 155 <= 150 is false. so, while loop stops.
// final value of num is 155
cout<< num; // output here is 155

Answer: 155
Add a comment
Know the answer?
Add Answer to:
num = 100; while (num <= 150) num = num + 5 ; cout<< num Assume...
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
  • 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;...

  • Please try to explain the answers as well. It will be highly appreciated. Output of the...

    Please try to explain the answers as well. It will be highly appreciated. Output of the following expression: 5 * 4 % 2 = ? Output of a loop: Example: What will be the output of the Java code (Assume all variables are properly declared.) num = 10; while (num <= 32)                 num = num + 5; System.out.println(num); What will be the output of the Java code (Assume all variables are properly declared.) public class test {   ...

  • What is the output? (3 pts) int num = 5; int* ptr = &num; cout <<...

    What is the output? (3 pts) int num = 5; int* ptr = &num; cout << ptr << endl; cout << &ptr << endl; cout << *ptr << 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 +...

  • Computer Science C++ Program What is the output? int num =5; int* ptr = # cout...

    Computer Science C++ Program What is the output? int num =5; int* ptr = # cout << ptr << endl; cout << &ptr << endl; cout << *ptr << endl; What are the values stored in the following array? Draw a simple picture of the array with indexes and show what each element should be. int arrayExample [4] = { 5 };

  • 18 C++ 1. What is the output of the following program segment? int y-22: while ((y...

    18 C++ 1. What is the output of the following program segment? int y-22: while ((y 3) != 0) cout << y<< "": y=y-2; The output is 2. Suppose that the input is 100, 20,-8, 50, 20. What is the output of the following C++ code? int sum0 int num: int j cin >> num: if (num < 0) continue зит зит + num; cout<< sum << endl; The output is

  • Language is C++ Complete the following Review Questions: 1. This is a control structure that repeats...

    Language is C++ Complete the following Review Questions: 1. This is a control structure that repeats a group of statements in a program? a. loop b. switch c. main() function d. compiler 2. In the expression number++,the ++operator is in what mode? a. Prefix b. Pretest c. Postfix d. Posttest 3.This is a variable that controls the number of iterations performed by a loop. a. Loop control variable b. Accumulator c. Iteration register variable d. Repetition meter 4. The do-whileloop...

  • 1. What would be the output of the following lines of code: int num = 2;...

    1. What would be the output of the following lines of code: int num = 2; switch(num){ case 1: cout << "1"; case 2: cout << "2"; case 3: cout << "3"; case 4: cout << "4"; } 2. What would be the output of the following code: char op = '*'; switch(op){ case '+': cout << "Addition"; break; case '-': cout << "Subtraction"; break; case '/': cout << "Division"; break; default: cout << "Invalid"; } 3. What would be...

  • c++ only. Please read directions. I'm looking to have each line re-written in a way that...

    c++ only. Please read directions. I'm looking to have each line re-written in a way that shows we're using the walk through method that the pointer is shifting by each value to solve this. Example far below shows what not to do.   Rewrite this program and remove the variable declared at line A below. Make your revised program generate the exact same output as the original without using the variable declared at line A. #include <iostream> using namespace std; int...

  • What is the output of the following C++ code? int count = 1; int num =...

    What is the output of the following C++ code? int count = 1; int num = 25; while (count < 25) { num--; count++; } cout << count « " " « num << endl i 25 1 0 24 1 0 25 0 0 24 0 In this while loop statement, while (counter < 10), where counter is an int variable. Which statement below is an equivalent way to write this while statement? while (10 < counter) while (9...

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