2.3 Code Practice: Question 1
Write a program that prompts the user to input two numbers, a numerator and a divisor. Your program should then divide the numerator by the divisor, and display the quotient and remainder.
Answers
Answer:
#include<iostream.h>
void main() {
int num, div;
cin >> num >> div;
int q, r;
q = num/div;
r = num % div;
cout << "Quotient: " << q << ", Remainder: " << r;
}
Explanation:
Include iostream to access cin, cout
Take input with cin
/ is used to divide two numbers, resulting in integer quotient for integers.
% is used to get the remainder
cout is used to display result on the screen
Following are the program for the above question:
Explanation:
numerator= float(input("enter the numerator: "))# It is used to take the value of numerator from the user.
divisor= float(input("enter the value of divisor: "))#It is used to take the divisor value from the user.
print("The quotient is: "+str(int(numerator/divisor))+" and the remainder is: "+str(int(numerator%divisor))) #It will prints the value of quotient and the remainder of the divison.
Output:
- If the user input as 12 and 3, then the output is 4 and 0.
- If the user input as 13 and 3, then the output is 4 and 1.
Code Explantion:
- The above code is in python language, in which the first and the second line will take the value of the numerator and the divisor.
- The third line is used to print the value of the quotient and the remainder. '%' operator is used to find the remainder.
Learn more:
- Python : https://brainly.in/question/14689905