Zebra0.com

cpp arithmeticAlgebra to code

Algebra to code

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 verify that the equation is correct. Use the following guidelines to convert
algebraic expressions to programming statements:

Algebra Program Explanation
XY x*y Algebra uses single letters for variables, and
can omit the *, programming languages always require an
operator.
X·Y x*y Algebra sometimes uses a dot for multiplication.
x squared x*x There is no way to type a smaller exponent.
x to the nth pow(x,n) Use #include <math> for power function.
squARE ROOT OF X sqrt(x) Use #include <math> for square root function.
a + b over c (a+b)/c Compound numerators and divisors must be enclosed in
parenthesis: Notice the difference between this example
and the one below:
a pluseb/c a/c+b Notice the difference between this example and the one
above.

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

NEXT: Math Functions