Algebra

Many times a programmer is given an algebraic formula, and must write an expression 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:

  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^2 Programming languages use only one line for equations: they can not write anything above or below the line.

  x to the z power X^Z The ^ operator is used for any power

  square root of x Sqrt(X) The System.Math.Sqrt function returns the square root

  a plus 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 plus b over c A+B/C Notice the difference between this example and the one above.


We will learn about using variables in the next lesson.


INDEX, Arithmetic Operations, Modulus Operator, Order of Operations, Functions, Algebra to Code
Next lesson: Visual Basic Variables

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Algebra to Code