Order this information in Print

Order this information on CD-ROM

Download in PDF Format

     

Click here to make tpub.com your Home Page

Page Title: Arithmetic Expressions
Back | Up | Next

tpub.com Updates

Google


Web
www.tpub.com

Home

   
Information Categories
.... Administration
Advancement
Aerographer
Automotive
Aviation
Combat
Construction
Diving
Draftsman
Engineering
Electronics
Food and Cooking
Math
Medical
Music
Nuclear Fundamentals
Photography
Religion
USMC
   
Products
  Educational CD-ROM's
Printed Manuals
Downloadable Books
   

 

Back
LET Statement
Up
Introduction to Programming
Next
Parentheses Rule

Back ] Home ] Up ] Next ]

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 it’s 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.

Back ] Home ] Up ] Next ]

 

Privacy Statement - Press Release - Copyright Information. - Contact Us - Support Integrated Publishing