Used to solve problems using a computer.

Key words in arithmetic expressions

Key words that can be used in problem statements contain mathematical operations.

Addition                
Key Words Examples              
Increase by Increase the total by 12  
More Than John earns R50 more than jack  
Combined Sam and Sallys combined points are 129  
Together Together, Thabu and jubu worked for 18 hours  
Total of Calculate the total of the first and second set of quantities  
Sum What is the sum of the prices of 3 items?  
Added to The 4th test mark must be added to the final mark  
   
Subtraction                
Keywords Examples              
Decrease by The final mark must be decreased by 10%  
Minus The amount minus the discount is the net amount  
Less Than Pete earns R20 less than Simon  
Difference The difference between my height and your height is 5cm  
Subtract from Subtract 15 from the accumulated points  
Between The difference between Thandis mark and Roses mork is 10  
Fewer than Goodman has worked five hours fewer than Samuel  
   
Multiplication                
Keywords Examples              
Of A quartor of 100 is 25            
Times The final mark is equal to all the marks times 1.5  
Multiplied by The wage is the hourly rate multiplied by the number of hours worked.  
Product of Calculate the product of the number of items and the price per item  
By factor of The total number must be increased by the factor of 12%  
                 
Division                
Keywords Examples              
Per Calculate the kilometres travelled per litre of fuel  
Out of 15 out of 60 is 25%  
Ratio If the ratio of girls to boys is 2:3 and there are 25 children, how many girls are there?  
Divided by Divide the number of minutes by 60 to get the number of hours  
Quotient of The quotient of 80 and 8 is 10  
Percent 50% percent of 250ml is 125ml  
   
Equals                
Key words Examples              
Is/are The sum of 20 and 12 is 32  
was / were The difference between my age and my grandmothers age was 60 years  
Will be The total of four numbers will be 300  
Equals The sum of 5 and 4 equals 9  
Give The prices of items bought give a total of R450  
Yields The calculation yields an answer of 36  
Sold for The final amount four items were sold for is R84  
Replaced by After an increase of 10% the new calculated amount can be replaced by the sales amount

 

Arithmetic expressions and equations

Equations are frequently used in arithmetic calculations

Example:     answer = 4+7

  • The calculation to the Right of the equal sign is done first.
  • The Result is assigned to the variable on the left of the equal sign which is “answer” in the example
  • After the statement is executed the variable called “answer” will contain a value of 11

The equal sign (=) has two meaning:

1: It can be used to assign a value to a variable.

total = 0                               ~     total is an integer variable

noOfStudents = 50             ~   noOf Students is an integer

 

2: It can be used to replace the value of a variable.

result = number * 2           ~   result and number are both numeric variables

sum = sum + points         ~     sum and points are both numeric variables

The last example  sum  = sum  + points will add the value of points to the value of sum to produce a new value for sum. The previous value of sum is increased by the value of the variable points.

If sum has a value of 200 and points has a value of 27, the right-hand side of the equation will be 200 + 27 and the new value of sum will be 227. The previous value of sum, which was 200, is now replaced by the new value, which is 227.

 

Arithmetic operators

Operator – is a symbol used within an expression or equation that tells the computer how to process the data.

This symbol joins the operands to be processed – for instance 3*6   3 and 6 are operands and * is the operator.

 

The following operators are used to perform arithmetic operations:

Arithmetic operators and the rules of precedence

Operator     Description                  Example     Result       Precedence

^                  Exponentiation             2^4                 16             1

(to the power of)

–                     Negation                         -TRUE           FALSE       2

– -6               +6

*,/               Multiplication and           5*7             35             3

Division                               72/8           9

\                  Integer division                 37\5           7                 4

mod           Modulus division               37 mod 5    2                 5

+,-               Addition and                     4+7               11               6

subtraction                        14-5               9

 

Integer division   —   Only done when dividing an integer value by another integer value, as it   discards (drops) the decimal part and dose not round the answer off.   49\10 =4

Modulus arithmetic   —   Only when the user wants to know what the value of the remainder is when dividing.

The order of precedence in execution is important. When an expression is executed.

  • It is always done from left to right
  • The operator with the highest order of precedence is done before others.
  • When operators with the same precedence occur in one expression. They will be executed from left to right

 

Examples:

5 – 3 ^ 2 \ 8 + 17 mod 3 *2

To find the answer of this expression, we need to determine which operator to execute first. The answers in the steps that follow have been underlined.

Step 1:   The exponentiation (3^2=9) is done first:

5 – 9 \ 8 + 17 mod 3 * 2

 

Step 2:     Multiplication and division are done from left to right: (3*2=6)

5-9\ 8 + 17 mod 6

 

Step 3:   Integer division (9\8=1)

5-1 + 17 mod 6

 

Step 4:   Modulus arithmetic ( 17 mod 6 =5)

5-1+5

 

Step 5: Lastly addition and subtraction from left to right.

4+5

9

Parentheses (or brackets) are used to change the order of execution.

Calculations in parentheses have higher value priority than any of the operators.

However the operators inside parentheses are executed according to the same order of precedence.

 

Example: Calculate the value of the variable k where k = a * b ^ (14 –c ) mod 4 + 3 \ a and where a, b and c are integer variables with the following values.

a= 3, b = 5, c = 11

Substitute the values of the variables before calculating:

K = 3*5 ^ (14-11) mod 4+ 3\ 3

= 3*5 ^ 3 mod 4 +3 \3

= 3*125 mod 4 + 3 \3

= 375 mod 4+ 3 \3

= 375 mod 4 + 1

= 3+1

= 4

Note that (14-11) is executed before the other operations because it’s in parentheses.

 

Setting up arithmetic equations

An arithmetic equation is also called an assignment statement in which variables and / or constants are assigned to a variable on the left –hand side of an equation.

Example: a = b + c where a must be a numeric variable that will contain the result , and b and c must also have numerical values, but may be constants or variables.

Computers cannot understand mathematical equations in the format we usually write them.

Variables and/or constants on the right –hand side of an equations are always separated by operands.

When writing arithmetic equations, the mathematical rules bust be applied (rules of precedence)

An equation only contains one variable to the left of the equation to store the result.

The following equation contains the variables:   X, A, B, C and D

 

The equation can now be written in computer- related format, as follows:

X = A ^ 3 – 2 * B + ( 2 * ( C +D ) ) / 2

Note how the brackets are used to execute the statements in the correct order.

Leave a Reply

Your email address will not be published. Required fields are marked *