Arithmetic Operations - Order of Precedence

Arithmetic Operations - Order of Precedence - 5 \ 2 ) + 29...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
VISUAL BASIC Arithmetic Operators Order of Precedence: ( ) Parentheses [always done in pairs] ^ Exponentiation - Negation * / Multiplication Division [have equal precedence] \ Integer Division Mod Modulo + - Addition Subtraction [have equal precedence] Examples: 16 = 2 ^ 4 25 = 5 ^ 2 204 = 3 * 17 *4 4.25 = 17 / 4 10.333 = 31 / 3 30 = 20 / 4 * 6 13.333 = 20 / 6 * 4 40 = 60 / 3 * 2 10 = 60 / ( 3 * 2 ) 27.5 = 11 * 5 / 2 300 = 3 * 10 ^ 2 4 = 17 \ 4 12 = 37 \ 3 12 = 36 \ 3 0 = 2 \ 3 1 = 19 \ 12 2 = 37 \ 3 \ 5 1 = 17 Mod 4 1 = 37 Mod 3 0 = 36 Mod 3 2 = 2 Mod 3 7 = 19 Mod 12 2 = 19 Mod 12 Mod 5 3 = 57 \ 5 Mod 4 2 = 67 \ 10 Mod 4 1 = 29 Mod 10 \ 4 0 = 18 Mod 14 \ 4 30 = ( 20 \ 3 ) * 5 1 = 20 \ 3 * 5 6 = 4 + 7 – 5 2 = 4 – 7 + 5 -8 = 4 – ( 7 + 5 ) -31 = 4 – 7 * 5
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Two examples showing “work” of how answer is found. Hold = 40 Mod 7 * 2 \ 4 – ( 20 * 5 + 1 ) = 40 Mod 7 * 2 \ 4 – ( 100 + 1 ) = 40 Mod 7 * 2 \ 4 – 101 = 40 Mod 14 \ 4 – 101 = 40 Mod 3 – 101 = 1 – 101 = - 1 0 0 Temp = 30 * (
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 5 \ 2 ) + 29 Mod ( 55 / 5 2 ) + 7 = 30 * 2 + 29 Mod ( 55 / 5 2 ) + 7 = 30 * 2 + 29 Mod ( 11 2 ) + 7 = 30 * 2 + 29 Mod 9 + 7 = 6 + 29 Mod 9 + 7 = 60 + 2 + 7 = 62 + 7 = 6 9 *Note: When arithmetic operations have equal precedence, you go from left to right (technically the terminology is called associativity). When you have two sets of parentheses, the sets have equal precedence, so you still go from left to right, set by set. To confirm that the answers above are correct create a simple program in Visual Basic with two labels and a button (see left print screen). Next, code Button1 with the following code for a click event (all controls/objects are using default names): Private Sub Button1_Click( ByVal sender As System.Object, ByVal. . Label1.Text = 40 Mod 7 * 2 \ 4 - (20 * 5 + 1) e End Sub Lab l2.Text = 30 * (5 \ 2) + 29 Mod (55 / 5 - 2) + 7 Run the program, click on Button1, and the final answers should appear in the labels (see right print screen)...
View Full Document

Page1 / 2

Arithmetic Operations - Order of Precedence - 5 \ 2 ) + 29...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online