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
For example, one might start with a population of 500 organisms, a growth rate of 2, and a growth period to achieve this rate of
maks197457 [2]

Answer:

The Python code is given below with appropriate comments

Explanation:

def predict_population_growth():

#Prompt and read the input from the user

num_org = int(input("Enter the initial number of organisms: "))

GR = float(input("Enter the rate of growth [a real number > 0]: "))

numHour = int(input("Enter the number of hours to achieve the rate of growth: "))

totalHours = int(input("Enter the total hours of growth: "))

#caluclate the total poulation growth

population = num_org

hours = 0

while hours < totalHours:

    population *= GR

    hours += numHour

print(" The total population is " + str(int(population)))

predict_population_growth()

6 0
3 years ago
What is one reason you might want to change your document's margins
Masteriza [31]

Answer:

1. If there is a big table or picture needed to show in a single paper.

2. For showing differences between two things.

3. To have more words to fit in a paper

Explanation:

6 0
3 years ago
Which of these is a good guideline when using text on a slide?
aleksklad [387]
Use no more than two font types
3 0
4 years ago
A technician installs a new WAP and users in the area begin to report poor performance. The technician uses a ping and only 3 of
krek1111 [17]

Answer: the correct answer is D. Spectrum Analyzer tool

Explanation:

A spectrum analyzer is a piece of electronic equipment that is used to gauge the magnitude (amplitude or strength) of a given input signal set against the full frequency range of the instrument. It is mainly used to measure the strength of the range of known and unknown signals.

4 0
3 years ago
Analog signals consists of individual electric pulses that represents bits group together into bytes {True/False}
Maru [420]

Answer:

The answer would be true

Explanation:

Hope this helps. Please mark me Brainliest

6 0
4 years ago
Other questions:
  • Which element in Access is an ideal data source?
    12·2 answers
  • Dani wants to create a web page to document her travel adventures. Which coding language should she use? HTML Java Python Text
    15·1 answer
  • 642<br> +277<br> What does 642+277
    7·1 answer
  • Which type of computer network ensures high quality​
    9·1 answer
  • Run a Monte Carlo simulation on this vector representing the countries of the 8 runners in this race:
    7·1 answer
  • What will be the code in CSS, to set
    8·1 answer
  • Hi I'm new to Brainly anyone wanna be my frnd​
    15·1 answer
  • I need help solving this problem on Picoctf. The question is What happens if you have a small exponent? There is a twist though,
    7·1 answer
  • Get ready to be the Quizmaster! You are going to design your own Python game show in the style of a quiz.
    13·1 answer
  • Match each type of video camera to its features:
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!