1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
zvonat [6]
3 years ago
7

4.14 LAB: Countdown until matching digits In C++ Write a program that takes in an integer in the range 20-98 as input. The outpu

t is a countdown starting from the integer, and stopping when both output digits are identical. Ex: If the input is: 93 the output is: 93 92 91 90 89 88 Ex: If the input is: 77 the output is: 77 Ex: If the input is: 15 or any value not between 20 and 98 (inclusive), the output is: Input must be 20-98 For coding simplicity, follow each output number by a space, even the last one. Use a while loop. Compare the digits; do not write a large if-else for all possible same-digit numbers (11, 22, 33, …, 88), as that approach would be cumbersome for larger ranges.

Computers and Technology
1 answer:
Fantom [35]3 years ago
6 0

Answer:

Here is the C++ program:

#include <iostream>  // to use input output functions

using namespace std;   // to identify objects like cin cout

int main() { //start of main function

   int number;  //an integer value

   cout<<"Enter an integer: ";  //prompts user to enter a number

   cin >> number;  // reads integer value from user

   if (number > 98 || number < 20) {  //if number is not between 20 and 98

  cout<<"Input must be 20-98";   }  //display this message if number is not between 20 and 98

 else {  // if number is in range 20-98

   while(number%11){  // loop keeps taking mod of input number with 11 until matching digits found

       cout<<number<<" ";  //displays the numbers

       number--;     }  // decrements the value of number by 1

    cout<<number<<" "; }  } // displays the matching digits

Explanation:

I will explain the program with an example:

Let suppose the number = 90

The if condition evaluate to false because 90 is in the range of 20-98 so the else part executes which has a while loop that works as following:

while(number % 11)

At first iteration:

This while(number % 11) is basically equivalent to :

while(number % 11 != 0)

while(90 % 11)

The % operator is the modulo operator which returns the remainder of the division. So when 90 is divided by 11 the remainder is 2. This is not equal to 0. So the statement under while condition executes:

cout<<number<<" "; This statement displays the number on output screen. Since number = 90 so 90 is printed. " " adds a space with the number

90

Next the value of number is decremented to 1 so number = 89

At second iteration:

while(number % 11) becomes:

while(89 % 11)

When 89 is divided by 11 the remainder is 1. This is not equal to 0. So the statement under while condition executes:

cout<<number<<" "; This statement displays the number on output screen. Since number = 89 so 89 is printed. " " adds a space with the number

90 89

Next the value of number is decremented to 1 so number = 88

At third iteration:

while(number % 11) becomes:

while(88 % 11)

When 89 is divided by 11 the remainder is 0. So the while loop breaks because the condition while(number % 11 != 0) evaluates to false. So the statement in while loop does not execute and program control moves to the following statement:

    cout<<number<<" "; This statement displays that number whose digits match on the output screen with a space. So the output of the entire program is:

90 89 88

The program along with the output using example given in the question i.e. input is 93 is attached in a screenshot.

You might be interested in
What are the first steps that you should take if you're unable to get onto the internet
sergij07 [2.7K]
Restart phone or go to settings
7 0
3 years ago
Read 2 more answers
Which is the most efficient way to insert a circle into a slide?
Alinara [238K]
Go to insert < shapes < ellipses < get yer circle
8 0
3 years ago
Write a summary of five things that you learned about CSS. Do not copy and paste the information. Summarize each point in your o
docker41 [41]

Answer:

We don't know what you leaned.

But, I'll do it anyway.

1. Getting id's from html content.

2. Getting classes from html content.

3. changing text fonts.

4. animation.

5. Getting all of one element type from html content.

Explanation:

Start from here.

5 0
3 years ago
Transmission Control Protocol (TCP) arrives out of order. What allows the data to be put back together in the correct order?
Reptile [31]

Answer:

Reliability feature in transport layer ensures correct order.

Explanation:

TCP (Transmission Control Protocol) is a communication protocol over network. TCP has a layered architecture and transport layer controls the data transmitted arrives in correct form. This is called reliability feature.

Control data header at transport layer ensures correct delivery. It tracks the transmitted data and re-transmits in case of en error.

7 0
3 years ago
Read 2 more answers
Question 4: Chess Game Knight's travails. Develop a data structure similar to a binary tree. Using a standard 8 X 8 chessboard,
zavuch27 [327]

Answer:

Answer: 64

Explanation:

5 0
2 years ago
Other questions:
  • Modify the Eggs program to create a new one named EggsInteractive that prompts the user for and accepts a number of eggs for eac
    13·1 answer
  • Assume you had a .csv file with data already populated that you wanted to use for a mail merge. Which button would you press to
    8·1 answer
  • What is a form of programming where multiple tasks can be carried out at the same time?
    10·1 answer
  • A high school student is working as a summer intern at your company. Explain to the intern how viruses, malware, and spam impact
    11·1 answer
  • As the Sunrise hospital implements an EHR, the coding staff requests a new system that will enhance productivity, accuracy, and
    15·1 answer
  • The number of pixels displayed on the screen is known as ​
    12·1 answer
  • Consider the following code: String word [] = {"algorithm", "boolean", "char", "double"}; for ( int i =0; i &lt; word.length/2;
    11·2 answers
  • What are some of the strategies that you use for confronting a complex problem and breaking it down into smaller pieces? How mig
    5·1 answer
  • 4.8 code practice question 1 edhesive
    8·2 answers
  • Which of the four factors of production are hit the hardest when high unemployment occurs ?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!