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
In a digital computer system, the data is transferred between the CPU and the other components
FinnZ [79.3K]

Answer:

The data transmission or information exchange from the CPU to either the computer's peripherals is accomplished via "Computer ports". The further explanation is given below.

Explanation:

To link a display, camera, microphones, or other devices, computer ports have several purposes. The Processor (CPU) also interacts through a bus to peripherals. Several categories of buses you must have got to hear of would be universal servo controller, PCI, or Compulsive-ATA.

  • A peripheral device has always been defined as any auxiliary appliance including a mouse as well as a keyboard, which somehow helps connect to either the PC but instead operates with it.
  • Computer systems were composed of various hardware. This would include the CPU, storage, buses, devices, etc.

So that the above is the right answer to the given scenario.

8 0
3 years ago
1. When adding text to an Excel worksheet, which option displays the Word window features? A. Text box B. There are no options t
shepuryov [24]
I'm gonna say A, hope it's right.
6 0
4 years ago
To make slides in a powerpoint online application presentation have the same transition effect, select __________ on the transit
Artemon [7]

Answer: Animations

Explanation:

Transitions, such as fade, can be applied to all using the command Ctrl+A.

Transitions are found under the animations Tab. Sorry about the bots.

Hope This Helped!

8 0
2 years ago
4.<br>d)<br>2 X 4<br>272 253<br>X Х<br>32 59<br>Х<br>3​
lawyer [7]

Answer:

idk what we are multipyling

Explanation:

please write out clearly so I can solve

6 0
3 years ago
8.6 Lesson Practice edhesive
scoundrel [369]

Incomplete question. I could only infer you are possibly referring to edhesive unit 8 questions. Here are a few sample questions;

1. Where does Python start?

2. To create the body of a function, we ____________ the code.

Answer:

1. Main Section

2. Indent

Explanation:

1. It is a common rule in Python programming language when coding for for it to begin at the first part of the Main Section.

2. Indenting a code involves creating space or jumping a line away from the margin of the text dialogue box, thus the code written there becomes the body of the function.

8 0
4 years ago
Other questions:
  • _____ software can help a company manage security, enforce corporate strategies, and control downloads and content streaming fro
    11·1 answer
  • A computer programme that tells the computer how to perform particular tasks
    8·1 answer
  • Dell, previously the world’s number one PC manufacturer, has seen its market share shrink because of rivals copying its value ch
    7·1 answer
  • What is the small ribbon inside a microphone that pick up vibrations
    7·1 answer
  • (a) [5 pts] Suppose you purchase a wireless router and connect it to your cable modem. Also suppose that your ISP dynamically as
    13·1 answer
  • 1. What is a digital networking app?
    12·2 answers
  • Write a recursive function is_pow2(n) that returns True if the positive integer n is an integer power of 2, and False otherwise.
    9·1 answer
  • If anyone wants to ft heres the link
    6·1 answer
  • Which of the following can you use to judge source legitimacy?
    6·2 answers
  • According to the selection, speech-software developers are still striving to develop speech-recognition technology that —
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!