MIC 110

Operators

Order of operations and examples:

 Order Operator Mathematical Operation Example 1 ( ) Parentheses 2 ^ Exponentiation CubicSpace = Length ^ 3 8 = 2 ^ 3 3 - Negation - Num1 4 * or / Multiplication Division Total_Sales = Unit_Price * Count ClassAve = TotalScores / NumOfStudents 5 \ Integer Division (DIV). The whole number portion of the answer in a divison. The decimal posion is dropped. CarsCanFitIn = AreaOfLot \ CarDim 10 = 215 \  20 15 is leftover 5 MOD Integer Remainder Division. The whole number portion of a remainder in a division. If the divider is greater than the number it is dividing, then the number become the remainder of the MOD division. BoothSpace = AreaOfLot MOD CarDim 15 = 215 MOD 20 BoothSpace = 3 MOD 10 3 = 3 MOD 10 7 + or - Addition Subtraction Total = Num1 + Num2 Profit = Sales - Expenses & String concatenation FullName\$ = First\$ & Last\$

Example of Integer Division (\) and Mod: Calculate the maximum number of seats to put in an airplane with 32 M2 floor space. Each seat takes 3 M2. How?

FloorSpace = 32
SeatSpace = 3
NumberOfSeats = FloorSpace \ SeatSpace
SpaceForLabs = FloorSpace Mod SeatSpace

Example of steps:

 For an expression Total = 10 + 15 * 2 / 4 ^ 2 - (2 + 3) , the order of computation is the following: Total = 10 + 15 * 2 / 4 ^ 2 - (2 + 3) Total = 10 + 15 * 2 / 4 ^ 2 -(5) Total = 10 + 15 * 2 / 16 -(5) ( 5 as a negative value) Total = 10 + 15 * 2 / 16 - 5 Total = 10 + 30 / 16 - 5 Total = 10 + 1.875 - 5 Total = 11.875 - 5 Total = 6.8

Another example:

 Step 1 intTotal = 2 * 5 ^ 2 + 3 * 5 + 7 Step 2 intTotal = 2 * 25 + 3 * 5 + 7 Step 3 intTotal = 50 + 3 * 5 + 7 Step 4 intTotal = 50 + 15 + 7 Step 5 intTotal = 65 + 7 Step 6 intTotal = 72

Here is a program that you can practice operators (Executable | Project | Form). It should help you to understand MOD, DIV and Division operators.