Programming in C - Doing the Math ( or 1 2 3.... here we go!



No Programming Language is worth it's weight in sand unless it can perform math. Not just accounting programs, but even graphics, games and music programs must have complex mathematical functions in order to make things happen. And the BEGINNING of math in computers is ALGEBRA.

Algebra may sound scary, but really it's not. All it is is... using LETTERS instead of NUMBERS. The concept may sound difficult, but it's not. Let's think about this for a minute:

If we say that the letter A is equal to the number 2:
Then what would 2 plus A be equal to?


Now just substitute the A for the number that we know it is. If we know that A = 2, and we know that 2 + 2 = 4, then:


Just in case you didn't catch that... I'll throw it again. You're just substituting the A with a 2 in your mind, and doing the simple math you already know! Now that wasn't so hard was it? Just to make sure you've got it, we're gonna try one more:


3 + A = 8 because A = 5 and  3 + 5 = 8



In Algebra, we commonly use mathematical operators of addition, subtraction, multiplication and division. Years ago, computer programmers decided that they would change the math symbols a little bit to make them easier to type into a computer. The math symbols look like this:

You are probably familiar with all these except the %. The % is used as the left over of a mathematical division problem... the remainder we called it in gradeschool. We know that 7 / 2 = 3, but that it leaves a remainder of 1. We could make it a fraction, but what if we wanted to use that remainder for something special? That's what the % was invented for.
Now that we've got the basics of Algebra down, we move on. In Algebra, Letters that are used in place of numbers are called VARIABLES, because their number can vary. For instance, if in the previous example, we had used a 10 for the letter A, the answer would have been 13, because 3+10=13. By varying the value of the letter A, we can come up with any number of possible answers. This makes VARIABLES much more flexable than fixed numbers.

In C, Variables can have several different types:
which are standard numbers like 3, 5 7 or 255.