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
- The 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_forwardexplain each code line. all the details.arrow_forwardWhat's wrong with this code? float q;int *p;q = 100.7;p = &q;arrow_forward
- Write at least one difference between int vs integerarrow_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. Cast f as an integer to a variable y. Cast d as float to a variable z. Hint: You have to initialize the variables x,y and z of proper data typesarrow_forwardCreate a program in C language that calculates the month's day from a given year and year's day. Use pointers for the month and month's day variables. Don't forget to add proper errors handling in your program. Example or errors - Invalid Input- Invalid year- Invalid year day Example of input # ./month_day <year> <yearday> # Example for Feb 2nd, 2019:\$ ./month-day 2019 33Feb 02, 2019 I have this class - month-day.c - #include <stdio.h> /* month_day function's prototype*/void month_day(int year, int yearday, int *pmonth, int *pday); int main() {return 0;} Note: I don't need the calendar, please read the instructions well!!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_forwardhexadecimalWe usually write numbers in decimal form (or base 10),meaning numbers arecomposed using 10 different “digits” f0; 1; : : : ; 9g.Sometimes though it is useful to write numbers hexadecimal or base16. Now there are 16 distinct digits that can be used to form numbers:f0; 1; : : : ; 9;A; B; C;D; E; Fg. So for example, a 3 digit hexadecimalnumber might be 2B8.(a) How many 2-digit hexadecimals are there in which the first digitis E or F? Explain your answer in terms of the additive principle(using either events or sets).(b) Explain why your answer to the previous part is correct in termsof the multiplicative principle (using either events or sets). Whydo both the additive and multiplicative principles give you thesame answer?(c) How many 3-digit hexadecimals start with a letter (A-F) and endwith a numeral (0-9)? Explain.(d) How many 3-digit hexadecimals start with a letter (A-F) or endwith a numeral (0-9) (or both)? Explain.arrow_forwardWrite application that prints matrix with rows and columns, number of rows and columns are input parameters (Have main method) Use DART programming languagearrow_forward
- Consider this code: "int z = 20; int sum = z++ + --z;". What are the values of z and sum? A. z is 20 and sum is 38 B. z is 19 and sum is 38 C. z is 20 and sum is 39 D. z is 19 and sum is 39 E. z is 20 and sum cannot be determinedarrow_forward@@@arrow_forwardC++ You are required to write a universal calculator that performs DOUBLE UP of different types of data. Especially the calculator must take the following types of input. A decimal number A float point number A binary number which must be prefixed with “0b”(e.g 0b111 ob1010 are valid 01b1010, 0b101, 01010 are invalid) A hexadecimal number which must be prefixed with “0x” (e.g. 0x19, 0xAAare valid. 01x1A, ox1A, 01A are invalid) Note Your program must implement function overloading. You can consider the examples below for your implementation. You are provided with the initial code which can be found. #include <iostream> #include <string> #include <string.h> #include <iomanip> using namespace std; /* * IMPLEMENT YOUR OVERLOADED FUNCTIONS HERE */ /* this function takes a string and * returns 1 if the string represents a decimal * returns 2 if the string represents a floating point * returns 3 if the string represents a binary * returns 4 if the…arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning