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
Rachel typed two paragraphs and then realized she was in the wrong document. What steps should Rachel follow to quickly move the
igomit [66]
It would be A. I hope that this helps!
6 0
3 years ago
Read 2 more answers
true of false one reason to move to a paperless society is that printers are becoming prohibitively expensive
Yakvenalex [24]
True because printers, which require paper, are becoming more expensive. A paperless society has the advantage of being cheaper in this aspect.
5 0
3 years ago
Stock ____ firms trade financial securities between a buyer and a seller.
diamong [38]
<span>Stock market firms, also known as brokerage firms, assist in the act of buying and selling financial securities. These trades are financed through financial institutions for security.</span>
3 0
3 years ago
33. (03.03 LC)
vodka [1.7K]

Answer:

False

Explanation:

Technology enhances the smooth run of businesses around the world at large. take an example of your transport systems, communication systems and even to advertisment of company products/services

5 0
3 years ago
What is a shot sequence
Elan Coil [88]
A shot sequence is the time between when a shot is shot and when it lands
7 0
3 years ago
Other questions:
  • Use the SQL Server Management Studio to complete the following.
    9·1 answer
  • To hide gridline when you display or print a worksheet
    14·1 answer
  • Does anyone have the GCSE 2018 Design Technology J310/01 practice paper?
    15·1 answer
  • Power point presentation make use of pages known as
    9·2 answers
  • HI How are you anyways are any of you intreseted in my giveaway
    7·2 answers
  • What are 3 similarities and 3 differences between live theatre and film/videos -Drama Class
    13·1 answer
  • Java can be procedural or object-oriented when it comes to programming. What is the difference between procedural and OOP?​
    13·1 answer
  • What is computer system ?​
    9·2 answers
  • AfcAAgrwdsgsFsefvzsdfvbjhbdjbbjbjsdndVHFadbhZJBVdb
    10·2 answers
  • In large organizations, database design and management is handled by a database _____.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!