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
Which OS does NOT provide users with a GUI?
vesna_86 [32]
The answer is C ms-dos
Side note:
GUI means graphical user interface. In other words, that means it looks pretty and has cool buttons, animations and cute stuff. MS-DOS is just a black screen with words on it. Definitely not cute or cool.
3 0
3 years ago
You manage a network that uses a single switch. All ports within your building connect through the single switch. In the lobby o
Karo-lina-s [1.5K]

Answer:

<u>VLANs</u>

Explanation:

Virtual LANs (VLANs) are a type of network connection or arrangement of network devices in the same broadcast domain. They are called Virtual LANs because they represent fractions or subgroups in the switch ports found in an Ethernet LAN.

Indeed, because of their topological arrangement, this reduces the security risk of unauthorized access to sensitive data or devices since the host can be placed on a different VLAN. Hence, in this scenario, using this network feature would allow visitors to plug into these ports to gain internet access, but they would not have access to any other devices on the private network.

5 0
3 years ago
What type of organism forms the base of food webs?
kotegsom [21]
A producer <span>forms the base of food webs</span>.
7 0
3 years ago
Write c++ program to find maximum number for three variables using statement ?​
pantera1 [17]

Answer:

#include<iostream>

using namespace std;

int main(){

int n1, n2, n3;

cout<<"Enter any three numbers: ";

cin>>n1>>n2>>n3;

if(n1>=n2 && n1>=n3){

cout<<n1<<" is the maximum";}

else if(n2>=n1 && n2>=n3){

cout<<n2<<" is the maximum";}

else{

cout<<n3<<" is the maximum";}

return 0;

}

Explanation:

The program is written in C++ and to write this program, I assumed the three variables are integers. You can change from integer to double or float, if you wish.

This line declares n1, n2 and n3 as integers

int n1, n2, n3;

This line prompts user for three numbers

cout<<"Enter any three numbers: ";

This line gets user input for the three numbers

cin>>n1>>n2>>n3;

This if condition checks if n1 is the maximum and prints n1 as the maximum, if true

<em>if(n1>=n2 && n1>=n3){</em>

<em>cout<<n1<<" is the maximum";}</em>

This else if condition checks if n2 is the maximum and prints n2 as the maximum, if true

<em>else if(n2>=n1 && n2>=n3){</em>

<em>cout<<n2<<" is the maximum";}</em>

If the above conditions are false, then n3 is the maximum and this condition prints n3 as the maximum

<em>else{</em>

<em>cout<<n3<<" is the maximum";}</em>

return 0;

3 0
3 years ago
Which rules should be remembered when creating formulas using nested functions? Check all that apply.
White raven [17]

Answer:

Use an equal sign at the beginning of the formula (A)

Use open and close parenthesis for each set of nested functions (B)

Functions should be in CAPS

Separate functions with commas

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • How do the search methods differ for primary and secondary data?
    10·2 answers
  • Information is a valuable asset and not everyone in the world can be trusted with it. Therefore, we need to protect our valuable
    10·1 answer
  • Lenovo's ThinkPad laptop computers is designed in the United States, the case, keyboard, and hard drive are made in Thailand; th
    14·1 answer
  • In which step of writing a program does a programmer first use a<br> compiler?<br> documentin
    6·1 answer
  • Andy is trying to put together a holiday gift knapsack (with W=8) for Sarah. He has n items to choose from, each with infinitely
    15·1 answer
  • Description:
    7·1 answer
  • 1.) Florida has ____________ roads that are designated as part of the National Highway System.
    12·1 answer
  • Categorize each of the following situations as a compile-time error, run-time error, or logical error. Group of answer choices m
    5·1 answer
  • Whose task it is to ensure that the product flows logically from one step to another?
    14·1 answer
  • What is the difference between algorithm and program?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!