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
Im bored anyone up for a convo? lets talk.. =D
aleksandrvk [35]

Answer:

ok im fine with dat <3

6 0
3 years ago
Read 2 more answers
Which icon is greater in file size? (Show your working)
nadya68 [22]

Answer:

the 256 color icon would be greater in file size.

Explanation:

regardless of how many pixels are in the image, file A has 256 colors meaning the computer has to individually load each one of those colors. it'll probably use a lot of ink if you decide to print it, too.

5 0
3 years ago
Technician A says that wheel speed sensors are a highly probable cause of illuminated EBC warning lamps. Technician B says that
Blababa [14]

Technician A because

3 0
2 years ago
____ of risk is the choice to do nothing to protect an information asset and to accept the outcome of its potential exploitation
umka21 [38]

Answer:

b. Acceptance

Explanation:

<em>"Acceptance </em><em>of risk is the choice to do nothing to protect an information asset and to accept the outcome of its potential exploitation.  </em><em>"</em>

<em>Acceptance Control </em>is important as a strategy when an organization has accomplished a determined level of risk, or it has estimated potential damages that might happen due to attacks, or the organization has developed a thorough analysis related to cost benefits, or it has also evaluated the probabilities of attacks.

7 0
2 years ago
_______________ provides options for getting access to your old password or resetting the account to a temporary password; users
gtnhenbr [62]

Answer:

account recovery

Explanation:

account recovery, provides options for getting access to your old password or resetting the account to a temporary password; users will change to a permanent password upon first login.

3 0
2 years ago
Other questions:
  • business owners and managers may first balk at the idea of mobile officer workers because there may appear to be a lack of ___ w
    9·1 answer
  • You can use RWA to demonstrate how to do something special on the web, such as displaying articles found on websites that suppor
    15·1 answer
  • List at least three benefits of automated testing?
    13·1 answer
  • It is impossible to use a computer without a mouse. Is this statement true or false?
    10·1 answer
  • Malwar is the short form for malicious software and used to refer​
    14·1 answer
  • Before posting a picture online, make sure to
    7·1 answer
  • It's fill the gap homework
    7·1 answer
  • Do u have all the subjects​
    12·2 answers
  • what is the term for software that is exclusively controlled by a company, and cannot be used or modified without permission?
    6·1 answer
  • Write a FOR loop that displays the following numbers exactly like this (you must use a loop):
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!