Integer division:
When both operands are integer data types, the resultant statement will be in integer division which means the outcome of the division will also be an integer data type. If there is a remainder, it must be ignored.
Example:
The example for the integer division is as follows:
double value;
value = 5 / 3;
In the above example, the outcome of the “5” by “3” is stored in the variable “value”. The value “1” is stored in the variable “value” because both “5” and “3” are integers, so the decimal part of the result must be truncated.
Floating-point division:
When both operands are floating-point or any one of the operand is a floating-point, the resultant statement will be in floating-point division, which means the outcome of the division will be a floating-point data type.
Example:
The example for the floating-point division is as follows:
double value;
value = 5.0 / 3;
In the above example, the result of the “5.0” by “3” is stored in the variable “value”. The value “1.6667” is stored in the variable “value”, because “5.0” is the floating-point data type and “3” is an integer data type, so the result has a floating-point value.
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
STARTING OUT WITH C++ MPL
- Question 1a. What digits are used in the binary number system?b.What digits are used in the decimal number system?c.What digits are used in the octal number system?d.What digits are used in the hexadecimal number system? \ Question 2In the following program, there is a call to the print_in_reverse function whichhas the following prototype: void print_in_reverse(float *a, int count); Using pointers, write this function to print the array in reverse order. #include <stdio.h>#define A_SIZE(A) sizeof(A)/sizeof(A[0]) void print_in_reverse(float a[], int count);int main(void) { float values[6] = { 12.1F, 22.2F, 32.3F, 42.4F, 52.5F, 62.6F }; printf("The array in reverse\n"); print_in_reverse(values, A_SIZE(values)); return 0;} Question 3The program below reads two integers. Then a function with the followingprototype is called: void div_rem(int a,…arrow_forwardThe following variables have been initialized for you: int a; float f: double d: You have to cast the variable into different data types as follows: • Cast a as float to a variable x. • Cest fas an integer to a varieble y. • Cest d as flost to a variable z. Hint: You nae to initia ize the varlebles xy and z of proper data types. Note: The required code to take user input is already written for you. Similar to value asinput. Sample Input 11 12.2345 12.34567895343534511 Sample Output: =110y-12z=12.3-5679arrow_forwardConvert the following statement to a statement that uses the universial quantifier:"There is no largest integer."arrow_forward
- What's wrong with this code? float q;int *p;q = 100.7;p = &q;arrow_forwardplease solve the question new solution, don't copy other solutions in questions bank c++ In this task, you are required to write a code that converts an Octal number into its equivalent Decimal value or vice versa. The user first selects the conversion choice by inserting 1 or 2. Choice 1 is followed by inserting an Octal integer and getting its Decimal equivalent value as an output. Choice 2 requires inserting a Decimal integer and prints out its Octal equivalent. The Octal numeral system, is the base-8 number system, and uses the digits 0 to 7, that is to say 10 octal represents 8 Decimal and 100 octal represents 64 Decimal. Convertion from an Octal integer into Decimal In the Decimal system, each number is the digit multiplied by 10 to the power of its location (starting from 0). For example: 74 decimal = 7 x 10^1 + 4 x 10^0 1252 decimal = 1 x 10^3 + 2 x 10^2 + 5 x 10^1 + 2 x 10^0 each number is the digit multiplied by 8 to the power of its location (starting from 0).…arrow_forwardWrite a function that checks whether an integer is an even digit or an odd digit integer using the following header: int getType(int n)arrow_forward
- Write a program that computes the number of extraterrestrial civilizations capable of communicating with us. - The program should use the following as constants in accordance with Drake's calculations: R. = 1, f = 1, f₁ =1 - The program should prompt the user for the values of every other variable and store those variables as a data-type that makes sense given the type of information that the variable represents. - The program should compute the number of civilizations, N, and write this value to the console window.arrow_forwardfunction avg and pass x and y Tin printf ("the avg of x and y is %d\n', avgl) give_sqrt (avgl); return 0, float avg (float m, float n) I/ Return the average of n and m void give sqrt (float x) printf ('the sqrt of is Mn'x :/ Print the sqrt value of x. return;arrow_forwardIndicate which of the following two declarations are valid or invalid. If invalid, give reason. int primes = {2, 3, 4, 5, 7, 11}; float elapsedTimes[] = {11.47, 12.04, 11.72, 13.88};arrow_forward
- Question 2 A number in base 2 (binary) is a number such that each of its digits is O or 1. To convert from binary to decimal (base 10), the digits starting from the right are multiplied by powers of 2 (starting at 0) and added. For example, the value in decimal of 10011 is calculated as follows: Write a program that reads from the user a 5-digit integer representing a value in binary and displays its equivalent value in decimal. Note that if the user enters an integer which digits are other than 0 or 1, the program displays a message stating that the number is invalid. Sample Run 1: Enter a 5-digit integer made of Os and 1s: 10011 10011 in decimal is 19 Sample Run 2: Enter a 5-digit integer made of Os and ls: 13001 13001 is not validarrow_forwardWhich integer data types can only hold non-negative values?arrow_forwardC programming language questionarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning