Original algorithms were mathematical procedures, example:
Special form of English. Ingredients are the "data".
Special notation:
Automatic execution by a machine:
Program flowchart: Raptor programming language
// sumDown.cpp // input number, if positive loop summing down to 0. Repeat until 0. #include <iostream> using namespace std; int main () { int num, sum, i; do { cout << "Enter a number: "; cin >> num; if (num >= 0) { sum = 0; for (i=num; i>0; i--) sum += i; cout << "sum=" << sum << endl; } } while (num != 0); }Same program in Python:
#sumDown.py #input number, if positive loop summing down to 0. Repeat until 0 is input. num = eval(input("Enter a number: ")) #first number from user while num != 0: #until a 0 is entered if num > 0: sum = 0 for i in range(num,0,-1): #loop down to zero, adding each number to the sum sum += i print("Sum is", sum) num = eval(input("Enter next number: "))The above C++ and Python program would be compiled into something similar to the following program in IBC (Itsy Bitsy Computer) assembly language:
/ program to read number, count down to 0, summing. / repeat for positive numbers Start: In 102 / user input Load 102,r1 / to r1 Load #0,r0 / 0 to r0 Cmp r1,r0 / compare user's input with 0 Beq done / done if user input a 0 Load #0,r6 / the sum Load #-1,r2 / the decrement value Next: Add r1,r6 / r6 += r1 Add r2,r1 / r1-- Store r1,106 Out 106 / display current value Cmp r0,r1 / =0 yet? Bne next / if not, loop back to Next Store r6,108 / but if 0, store sum Out 108 / display sum Jmp start / do another Done: HaltRaptor flowchart language version: