Algebra

Many times a programmer is given an algebraic formula, and must write an assignment statement that will correctly calculate the answer. After writing a statement, check it by hand, using sample values and
the method shown above to verify that the equation is correct. Use the following guidelines to convert algebraic expressions to programming statements:

AlgebraProgramExplanation:
XY $x*$yAlgebra uses single letters for variables, and can omit the *, programming languages always require an operator.
X·Y $x*yAlgebra sometimes uses a dot for multiplication.
2X$x*2Programming languages always require an operator.
square $x*$x There is no way to type a smaller exponent.
X to the nth power pow($x,$n) PHP has lots of built in functions, check the manual!
square root sqrt($x) another built in function
fraction ($a+$b)/$c Compound numerators and divisors must be enclosed in parenthesis: Notice the difference between this example and the next one.
fraction $a+$b/$c  


Remember: Algebra uses single letters for variables: programmers should use good variable names wherever possible!

Note: While you are looking at all of built in functions, take a look at the rand function, then go to the test page to roll dice.

rand returns a random integer number. If we find the remainder when dividing by 6 we get a value from 0 to 5. Add 1 to get values from 1 to 6.


INDEX, Arithmetic Operations, Order of Operations, Algebra
Next lesson: Boolean Expressions and ConditionalsMAIN INDEX
EXAMPLES INDEX

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Algebra