Math Cheat Sheet for Programmers

This page is a cheat sheet of common mathematical formulas for programmers. It is written with BASIC in mind, but can be easily converted to your programming language.

## Arithmetic

**Addition**`z = x + y`**Subtraction**`z = x - y`**Multiplication**`z = x * y`**Division**`z = x / y`

## Area

**Area of Square**`area = length * height`**Area of Rectangle**`area = length * height`**Area of Triangle**`area = (base * height) / 2`

## Ratios

**Fraction to Ratio**`ratio = denominator / numerator`**Odds to Ratio**`ratio = against / for`

## Percents

**25% of 60**`z = 0.25 * 60`**Add 25% to 60**`z = (1 + 0.25) * 60`**Remove 25% from 60**`z = (1 - 0.25) * 60`

## Exponents

**Squared**`squared = x * x`**Cubed**`cube = x * x * x`

## Other

**Slope**`slope = distance / height`or`slope = run / rise`**Absolute Distance (horizontal)**`distance = abs(x1-x2)`**Absolute Distance (vertical)**`distance = abs(y1-y1)`**Relative Distance (horizontal)**`distance = x1 - x2`**Relative Distance (vertical)**`distance = y2 - y2`**Euclidean Distance**`distance = sqr((x1-x2)^2 + (y1-y2)^2))`**Distance Traveled**`distance = time * speed`

## Unit Conversion

#### Length

**Feet to Inches**`inches = feet * 12`**Feet to Yards**`yards = feet / 3`**Inches to Feet**`feet = inches / 12`**Inches to Yards**`yards = (inches / 12) / 3`**Yards to Feet**`feet = yards * 3`**Yards to Inches**`inches = yards * 3 * 12`

#### Weight

**Ounces to Pounds**`ounces = pounds * 16`**Pounds to Ounces**`pounds = ounces / 16`

## Collision

**Circle**`if sqr((x1-x2)^2 + (y1-y2)^2)) <= (radius1 + radius2) then 'collision`

page revision: 10, last edited: 29 Aug 2007 15:33