Presentation is loading. Please wait.

Presentation is loading. Please wait.

Numbers.

Similar presentations


Presentation on theme: "Numbers."— Presentation transcript:

1 Numbers

2 Numbers Arithmetic Operations Display numbers in VB.NET Variables
Built_in Functions Three types of errors 12/1/2018 Numbers

3 Arithmetic Operations
Numbers are called numeric literals Five arithmetic operations in VB.NET + addition - subtraction * multiplication * 2 / division / 2 ^ exponentiation ^ 2 12/1/2018 Numbers

4 Precedence of Arithmetic operation
Level of precedence: () Inner to outer,left to right ^ Left to right in expression * / Left to right in expression + - Left to right in expression 12/1/2018 Numbers

5 Scientific Notation Scientific notation represents a number by using power of 10 to stand for zeros In VB.Net b • 10 r is written as bEr 12/1/2018 Numbers

6 Scientific Notation 10 –20 10 ^ - 20 1E-20
r is two digit number preceded by plus sign if r is positive and by a minus sign if r is negative 10 – ^ E-20 1.2 • * 10 ^ E+13 VB.NET’s choice of whether to display a number in a scientific or standard form depends on the magnitude of the number 12/1/2018 Numbers

7 Display numbers One way to show numbers on screen is to display them in a list box. lstNumbers.Items.Add(n) - Display number n as the last item in the list box lstNumbers.Items.Clear() - Erase all the items in the list box 12/1/2018 Numbers

8 Demonstration List a set of numbers in a list box. 12/1/2018 Numbers

9 Variables A variable is a name that is used to refer to an item of data. The value assigned to the variable may change. Up to 16,838 characters long Begin with a letter or an underscore Consist of only letters,digits and underscores A Variable name is written in lowercase letters except for the first letters of additional words, such as costOfIT201. 12/1/2018 Numbers

10 Data Type Type Stores Range Of Values Boolean Logical Values
True or False Double Float-Point Numbers +/- 5E-324 to 1.8E308 Integer Integers -32,768 to 32767 Long +/- 2 billion Single Floating Point Numbers +/- 1E-45 to 3E38 String Text Information Fixed Length: 1 to 65,400 12/1/2018 Numbers

11 Const constantName As dataType = value
Variable Declaration Declaration: Dim varName As dataType Variable name Data type Const constantName As dataType = value Variable that can’t change 12/1/2018 Numbers

12 Variable Declaration Dim declares a variable named varName to be of type dataType Dim causes computer to set aside a location in memory with the same name varName Dim also put the number zero in that memory location if varName is a numberic variable 12/1/2018 Numbers

13 Multiple Declarations
multiple-declaration statements : Dim a, b As Double Dim a As Double, b As Integer Dim c As Double = 2, b As Integer = 5 12/1/2018 Numbers

14 Variable Initialization
Numeric variables are automatically initialized to 0: Dim varName As Double To specify a nonzero initial value Dim varName As Double = 50 declares a variable named varName to be of type Double. Actually, the Dim statement causes the computer to set aside a location in memory with the name varName. Since varName is a numeric variable, the Dim statement also places the number zero in that memory location. (We say that zero is the initial value or default value of the variable.) 12/1/2018 Numbers

15 Assignment statement Assignment:(n is a literal) varName = n
varName = expression 12/1/2018 Numbers

16 Rules for assigning variables
Assign Integer, Long data type to a variable to store whole numbers Assign Single, Double to a variable to store decimal fraction Assign String to a variable to store a list of characters Assign Boolean data type to a variable whose value will be True or false Assign Date data type to a variable to store date and time information Assign Object data type to a variable to store reference to an object Choosing the data type in each group depending on the size o 12/1/2018 Numbers

17 Increment variable value
To add 1 to the numeric variable var var = var + 1 Or as a shortcut var +=1 12/1/2018 Numbers

18 Built-in Functions Functions associates with one or more values and returns a value(output) Math.sqrt(n): Returns the square root of n. Math.Sqrt(9) is 3 Int(n): Returns greatest integer less than or equal to n Int(9.7) is 3 12/1/2018 Numbers

19 Built-in Functions Math.Round(2.5) is 2 Math.Round(n, r):
number n rounded to r decimal places Math.Round(2.317,1) is 2.3 Math.Round(2.7) is 3 When n is halfway between two successive whole number, then it rounds to the nearest even number Math.Round(2.5) is 2 Math.Round(3.5) is 4 12/1/2018 Numbers

20 Three Types of Errors Syntax error – grammatical errors Run-time error
misspellings, omissions,incorrect punctuation Run-time error occurs when program is running Logic error program doesn’t perform as it is intended 12/1/2018 Numbers


Download ppt "Numbers."

Similar presentations


Ads by Google