Custom Search
 
  

 
ARITHMETIC EXPRESSIONS

Arithmetic expressions are composed of a combination of constants, variables, operation symbols, and functions. An expression may be very simple or quite complex, but it will result in a single value. Whether an expression is simple or complex, the calculations must be performed in a specific order. To ensure the computer will correctly evaluate and calculate arithmetic expressions, you have to learn to code them using the rules of BASIC. In order to use arithmetic expressions efficiently, you must be able to evaluate and convert conventional mathematical expressions into proper BASIC expressions.

Arithmetic Operators

Unlike algebra, each arithmetic operator in a BASIC expression must be specified by the inclusion of the appropriate operator symbol. The symbols with their operation are as follows:

Operator Symbol 

**



*

/

+

-

Operation 

Exponentiation (an up arrow is used on some computers)

Multiplication

Division 

Addition 

Subtraction 

The symbols associated with each operator are standard in the BASIC language. In mathematics its all right to write AB to mean multiply A times B. In BASIC you must write A*B since default conditions do not exist. This means if you forget one of the operator symbols, the compiler will not insert it for you; but rather will give you an error message.

Precedence Rule

Many expressions are complex and may have two or more operators; therefore, the computer must have specific rules of precedence to define the order of execution. The computer will perform exponentiation first, then multiplication or division, then addition or subtraction. That is, exponentia-tion has precedence over addition and subtraction. The following list shows the operator symbols, operation, and their precedence of execution.

Operator Symbol 

**

*

/

+

-

Operation 

Exponentiation

Multiplication

Division 

Addition 

Subtraction 

Precedence

1

2

2

3

3

If two or more operators of the same precedence appear in an expression, then the order of evaluation is from left to right.

Example:

Given: A = 10, B = 6, and C = 7

A and B will be added giving 16, then C will be subtracted giving 9.

B will be subtracted from A giving 4, then C will be added giving 11.







Western Governors University
 


Privacy Statement - Copyright Information. - Contact Us

Integrated Publishing, Inc. - A (SDVOSB) Service Disabled Veteran Owned Small Business