Arithmetic
programmingThe process of writing computer software.is writing computer code to create a program, to solve a problem. programSequences of instructions for a computer. are created to implement algorithmA sequence of logical instructions for carrying out a task. In computing, algorithms are needed to design computer programs.. Algorithms can be represented as pseudocode Also written as pseudo-code. A method of writing up a set of instructions for a computer program using plain English. This is a good way of planning a program before coding. or a flowchartA diagram that shows a process, made up of boxes representing steps, decision, inputs and outputs., and programming is the translation of these into a computer program.
To tell a computer to do something, a program must be written to tell it exactly what to do and how to do it. In order to do this, you need to know how programs are constructed.
Basic arithmetic
Arithmetic is used all the time in computer programs, so an understanding of how computers use arithmetic is useful. This table lists the common arithmetic processes with their programming equivalents:
Arithmetic process | Programming equivalent |
Addition (plus) | + |
Subtraction (minus) | - |
Multiplication | * |
Division | / |
Arithmetic process | Addition (plus) |
---|---|
Programming equivalent | + |
Arithmetic process | Subtraction (minus) |
---|---|
Programming equivalent | - |
Arithmetic process | Multiplication |
---|---|
Programming equivalent | * |
Arithmetic process | Division |
---|---|
Programming equivalent | / |
Computers can be programmed to carry out calculations 鈥 so long as the correct formulas to use are known. Some simple mathematical examples in PythonA high-level programming language. (3.x) are:
>>> print(5 + 7)
12
>>> print(7 - 5)
2
>>> print(5 * 7)
35
>>> print(35 / 7)
5.0
More complicated calculations can be performed too:
>>> print((5 * 2) + (4 - 3))
11
>>> print((8 / 4) + (2 - 1))
3.0