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
kupik [55]
3 years ago
6

#11. Write a program that prompts the user to input a four-digit positive integer. The program then outputs the digits of the nu

mber, one digit per line. For example, if the input is 3245, the output is:
Computers and Technology
1 answer:
JulsSmile [24]3 years ago
7 0

Answer:

<em>C++</em>

/////////////////////////////////////////////////////////////////////////////////////

#include <iostream>

using namespace std;

int main() {

   int number;

   cout<<"Enter four digit positive integer: ";

   cin>>number;

   ///////////////////////////////////////////////

   int divisor = 1000;

   int digit;

   

   if ((number > 999) && (number < 9999)) {

       for (int i=0; i<3; i++) {

           digit = number/divisor;

           number = number%divisor;

           divisor = divisor/10;

           cout<<digit<<endl;

       }

       cout<<number;

   }

   else {

       cout<<"Invalid range!";

   }

   ///////////////////////////////////////////////

   return 0;

}

Explanation:

To accomplish the task, we need to use the divide and modulo operators.

To get each digit, we need to divide the variable number by the divisor (which is initialized to 1000).

We also need to reset the number variable to one less digit from the right. We can do this by number modulo divisor, which is assigned back to the number variable.

Finally we need to lower the divisor by 10 each time in the loop, to keep it in accordance with the above two operations.

You might be interested in
Consider the following code snippet:public static void main(String[] args) throws FileNotFoundExceptionWhich of the following st
iVinArrow [24]

Answer:

The main method should simply terminate if the FileNotFoundException occurs.

Explanation:

Considering the full code snippet

snippet:public static void main(String[] args) throws FileNotFoundException

public static void main(String[])

represent the entry point method to a java main method

The addition of

throws FileNotFoundException

widens the scope of the main method to explicitly specifies that an exception named the FileNotFoundException may be thrown.

So, if any part of the code explicitly throws the FileNotFoundException the compiler makes use of this to throw an exception.

By throwing an exception, the main method is not catching any exceptions, instead it handles the FileNotFoundException by throwing it to the source which invoked the main method

This is required by the compiler to terminate the program if the FileNotFoundException occurs.

8 0
3 years ago
Ray owns a gaming cafe where users can play video games on computers. These games involve rich graphics and need high processing
tankabanditka [31]

Answer:

thick

Explanation:

i took the test and got it right

6 0
2 years ago
Pass the two arrays to a method that will display the integer value(s), if any, that appear in both arrays (note that the two ar
vampirchik [111]

Answer:

The solution code is written in Java

  1.    public static void checkCommonValues(int arr1[], int arr2[]){
  2.        if(arr1.length < arr2.length){
  3.            for(int i = 0; i < arr1.length; i++){
  4.                for(int j = 0; j < arr2.length; j++){
  5.                    if(arr1[i] == arr2[j]){
  6.                        System.out.print(arr1[i] + " ");
  7.                    }
  8.                }
  9.            }
  10.        }
  11.        else{
  12.            for(int i = 0; i < arr2.length; i++){
  13.                for(int j = 0; j < arr1.length; j++){
  14.                    if(arr2[i] == arr1[j]){
  15.                        System.out.print(arr2[i] + " ");
  16.                    }
  17.                }
  18.            }
  19.        }
  20.    }

Explanation:

The key idea of this method is to repeated get a value from the shorter array to check against the all the values from a longer array. If any comparison result in True, the program shall display the integer.

Based on this idea, an if-else condition is defined (Line 2). Outer loop will traverse through the shorter array (Line 3, 12) and the inner loop will traverse the longer array (Line 4, 13). Within the inner loop, there is another if condition to check if the current value is equal to any value in the longer array, if so, print the common value (Line 5-7, 14-16).

5 0
2 years ago
Where is Peru located?
Illusion [34]
B. South America

[ignore:20 CHARACTERS]
4 0
3 years ago
#Write a function called "scramble" that accepts a string #as an argument and returns a new string. The new string #should start
mojhsa [17]

Answer:

def scramble(s):

   if len(s) % 2 == 1:

       index = int(len(s)//2)

   else:

       index = int(len(s)/2)

   

   return s[index:] + s[:index]

Explanation:

Create a function called scramble that takes one parameter, s

Check the length of the s using len function. If the length is odd, set the index as the floor of the length/2. Otherwise, set the index as length/2. Use index value to slice the s as two halves

Return the second half of the s and the second half of the s using slice notation (s[index:] represents the characters from half of the s to the end, s[:index] represents the characters from begining to the half of the s)

8 0
3 years ago
Other questions:
  • What is the typical relationship between time and interest rate?
    12·1 answer
  • Why was the term personal computer created?
    5·1 answer
  • The following 2D array has been created:
    12·2 answers
  • This is the thing that I don't understand why did they banned private chat like there are long-distance relationships, and frien
    13·2 answers
  • At each layer of the OSI model, data is appended to the original message and then sent on to the next lower layer. What is this
    10·1 answer
  • Why is it so important to adhere to principles that have been put forth by reputable organizations to ensure that you are mainta
    10·1 answer
  • (I WILL GIVE BRAINLIEST) Which steps will delete an appointment?
    8·1 answer
  • I have tried many times to find a gaming setup for $4k. I have tried many websites but they are not working for my liking. Any o
    15·1 answer
  • I need help about computer program. Solve C language code...... please​
    7·1 answer
  • How do you modify WordArt? Give specific details and steps<br><br> NEED THIS ASAP
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!