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
Len [333]
3 years ago
5

Write a program that prompts the user to input two numbers, a numerator and a divisor. Your program should then divide the numer

ator by the divisor, and display the quotient and remainder.
Computers and Technology
2 answers:
12345 [234]3 years ago
8 0
What language? JavaScript? Python?
Fed [463]3 years ago
7 0

***NOTE: <em>Since the programming language is not mentioned in the question, I am going to answer it in Python, Java, and C++, so that you have an option to choose a language of your choice.</em>***

Requirements:

1. We need to ask a user to enter two numbers, a numerator and a divisor. So obviously we need to have two variable in order to store those values.

2. We have to display the quotient and the remainder. Although we do not need to have separate variables to those, as we can display them directly inside the <em>print </em>statement (of the respective programming language), it would, however, be a good practice to save them in the variables.

Please note that there is no requirement of checking the errors, but for simplicity, I am going to add one error-check when the user enters 0 as a divisor, which is not allowed (mathematically); otherwise, it would give you an error.

Also do not forget to read the comments within the code. Each and every step is explained.

Let's code it!

<u>Python Code</u>

<em># Prompt the user to input a numerator (number)</em>

numerator = int(input("Enter a numerator: "))

<em># Prompt the user to input a divisor (number)</em>

divisor = int(input("Enter a divisor: "))

<em># Making sure that the user does not enter 0 as a divisor</em>

if divisor != 0:

<em>    # We need to divide the numerator with the divisor to get the quotient</em>

   quotient = numerator / divisor

<em>    #We need to find the remainder by using the Modulus operator</em>

   remainder = numerator % divisor

   

<em>    #Now display both the remainder and the quotient using the print statement</em>

   print("The quotient is: {}".format(int(quotient)))

   print("The remainder is: {}".format(remainder))

else:

   print("Divisor cannot be equal to 0. Please rerun the program.")

<u>Java Code</u>

<em>// First import Java Scanner module for taking inputs from the user</em>

import java.util.Scanner;

public class HelloWorld{

    public static void main(String []args){

<em>         // initialise the scanner</em>

        Scanner input = new Scanner(System. in);

<em>        // Prompt the user to input a numerator (number)</em>

       System.out.print("Enter a numerator: ");

       int numerator = input.nextInt();

<em>        // Prompt the user to input a divisor (number)</em>

        System.out.print("\nEnter a divisor: ");

       int divisor = input.nextInt();

     <em> // Making sure that the user does not enter 0 as a divisor</em>

       if (divisor == 0) {

           System.out.println("Divisor cannot be equal to 0. Please rerun the program again.");

           return;

       }

<em>        // We need to divide the numerator with the divisor to get the quotient</em>

       int quotient = numerator / divisor;

<em>        // We need to find the remainder by using the Modulus operator</em>

       int remainder = numerator % divisor;

<em>        // Now print both the remainder and the quotient using System.out.println statement</em>

       System.out.format("\nThe quotient is: %d\n", quotient);

       System.out.format("The remainder is: %d\n", remainder);

    }

}

<u>C++ Code</u>

#include <iostream>

using namespace std;

int main()

{

       int numerator = 0;

       int divisor = 0;

<em>        // Prompt the user to input a numerator (number)</em>

       cout<<"Enter a numerator: ";

       cin>>numerator;

<em>        // Prompt the user to input a divisor (number)</em>

       cout<<"Enter a divisor: ";

       cin>>divisor;

       <em>// Making sure that the user does not enter 0 as a divisor</em>

       if (divisor == 0) {

           cout<<"Divisor cannot be equal to 0. Please rerun the program again.";

           return -1;

       }

<em>        // We need to divide the numerator with the divisor to get the quotient</em>

       int quotient = numerator / divisor;

<em>        // We need to find the remainder by using the Modulus operator</em>

       int remainder = numerator % divisor;

<em>        // Now print both the remainder and the quotient using "cout" statement</em>

       cout<<"\nThe quotient is: "<<quotient<<endl;

      cout<<"The remainder is: "<<remainder<<endl;

   return 0;

}

You might be interested in
What is the value of the result after the following statement is executed? int result = 2 + 3 + 4 ;
kow [346]

2 + 3 + 4 = 9 so the value of result is also 9

8 0
3 years ago
DUE SOON NEED HELP FAST!!
AleksAgata [21]

Answer:

From 2007 to 2016 the correct answer would've been Caracas, Venezuela. With a longitude of 66° 56' W.

Their timezone at that time was GMT-4.5, which means they'd be four and a half hours behind GMT.

As of 2021, there are no countries using that timezone for international trade and travel.

Explanation:

Had to make some assumptions. If no other context is given, then this would be the correct answer.

7 0
3 years ago
What is the<br>Way to<br>keep the tool<br>Screw​
Verizon [17]
What does that even mean? is this a poem?
7 0
2 years ago
If I want to make it look like slide number one is turning a page to slide number two, what
garik1379 [7]

Answer:

Im not certain but I think thwir is one called flip

Explanation:

Kind of works like a book if thats what your asking for

6 0
2 years ago
Can you give me a long list of anime
aleksley [76]
Kill la Kill
Evangaleon
Blue Exorcist
The Devil is a Part Timer
Berserk
Death Note
K
A Boring World Where The Concept of Jokes Does not Exist
Psycho Pass
Elfen Lied
Soul Eater
Fairy Tale
Naruto
3 0
3 years ago
Read 2 more answers
Other questions:
  • The gaining of unauthorized access to data in a<br> system or computer:
    11·1 answer
  • An administrator has noticed that GPO containing new update settings has not yet applied to one of the computers on the network.
    5·1 answer
  • What is meant by backing up files through cloud computing?
    5·2 answers
  • Both the Alphabetic Index and the Tabular List must be used to locate and assign a diagnosis code in ICD-10-CM. Group of answer
    7·1 answer
  • What is the "online disinhibition effect"?​
    7·1 answer
  • Nuclear batteries use devices called thermocouples, which convert the ____ of a nuclear reaction into electricity.
    9·1 answer
  • Select the four bad password ideas.
    13·2 answers
  • 25 POINTS PLATO
    6·2 answers
  • The TCP _____ is the amount of information that a machine can receive during a session and still be able to process the data.
    5·1 answer
  • Create a timeline of the evolution of computers and their impact on society
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!