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
14. Blender® does not typically use pop-up boxes. (1 point)
ivolga24 [154]
Hey buddy 

so 14 it was be a long time but l think it is true 

15 is <span>the range of tools and functions associated with that activity</span>
5 0
3 years ago
What function would you use to calculate the total interest paid for the first year of a mortgage?.
WITCHER [35]

Answer:

To calculate the total interest paid for the first year of a mortgage, the formula M = [P.r (1+r)n] / [(1+r)n-1] × 12 can be used.

Explanation:

3 0
2 years ago
Safety glasses should be worn in which of the following situations?
N76 [4]
When any substance is being heated. Safety glasses
8 0
2 years ago
3. How are you able to create photographs differently than 100 years ago?
Agata [3.3K]

Answer:

it willbe black and white

Explanation:

3 0
2 years ago
Read 2 more answers
An oligopoly is a unique market structure. Which of the following is NOT necessary to have a oligopolistic market structure?
Annette [7]
I would say A 
hope this helped ;)
sorry if im wrong 
7 0
3 years ago
Other questions:
  • Under what conditions might the Justice Department approve a merger between two companies that operate in an industry with a pos
    14·1 answer
  • The base class Pet has private fields petName, and petAge. The derived class Dog extends the Pet class and includes a private fi
    6·1 answer
  • I want to know all part of computer system?
    9·2 answers
  • is this statement true or false ? satelite and remote sensing devices have helped cartographers make more accurate maps with spe
    12·1 answer
  • Write a program in c++ that asks the user for a sequence of n​integers, where the user provides the number of elements n​ then e
    12·1 answer
  • As part of the systems engineering development team, use IDEF0 to develop a functional architecture. The functional architecture
    13·1 answer
  • Whoever answers first gets lots of points
    14·2 answers
  • Match the job roles with their appropriate qualifications. business analyst multimedia artist network and computer systems admin
    9·2 answers
  • The type of medium used to hide data in steganography is referred to as __________. This may be a photo, video, sound file, or V
    12·2 answers
  • (1) Prompt the user to input an integer, a double, a character, and a string, storing each into separate variables. Then, output
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!