You are on page 1of 12

Computer programs

A computer follows the instructions given by the programmer to perform a specific job or task.
To perform a particular task, programmer prepares a sequence of instructions, known as
programs. A program written for a computer is called a computer program. Computer
programs also called software or applications are stored inside the RAM. The CPU takes one
instruction of the program at a time from the RAM and executes it. The instructions are executed
one by one in sequence and finally produce the desired result. The process or act of
writing/creating programs is called programming (also called scripting) and person who write
this programs is called a programmer (or software developer/designer).
Program can be divided into two forms syntax and semantics. Syntax means the structure
and/or flow of the program. Semantics indicates the meaning of the syntax.
Programming languages
A programming language is a language for writing programs for a computer.
Computer programming languages are any of various languages for expressing a
set of detailed instructions for a digital computer. Programming languages are
mainly used to control the performance of a computer or to express algorithms. At
present, there are thousands of programming languages have been implemented.
General speaking, we can classify programming languages into two categories:
Low-level programming languages and High-level programming languages.
1. Low-level programming languages, LLL: are those which require a
programmers to manage explicitly all of a computer’s characteristic features of
data storage and operation, i.e., the programmer has to know the architecture of the
computer. We have two types of low-level programming languages the machine
language and assembly language.

A. Machine language, ML (also called Binary language): consists of numeric


codes for the operations, like addition, that a particular computer can executes
directly. The codes are strings of 0’s and 1’s, or binary digits (bits), that is why it is
called Binary language. Since computer understand only 1’s and 0’s we can call
machine language is the natural language of a computer, for that reason computer
can executes programs written in ML very fast, i.e., ML is the only language that a
computer can understand. Also ML is called object code.
Example: ML to add two values:
0010 0000 0000 0100
0100 0000 0000 0101
0011 0000 0000 0110
B. Assembly language, AL (also called Symbolic language): is one level above ML.
AS
Uses short mnemonic code for instructions and allows the programmer to introduce
names
For blocks of memory that hold data. AL is designed to be easily translated into ML. the
program or software that translate each AL instruction word to ML binary code is called
Assembler and the process is assembling.
Example: the equivalent code for the above ML can be:
LOAD a
ADD b
STORE c
Like ML, AL requires detail knowledge of the computer architecture; hence both
languages are hardware dependent therefore LLL needs hardware modification.

2. High-level programming languages, HLL: are machine independent, more English-


like, and more natural. High-level programming languages are also called Compiler
languages. Each high-level language statement has to be translated to several low-level
language statements so as to it is the computer can understand. We have two ways of
converting HLL to LLL; compiling or interpreting.
Complier is translator program that transform high-level program code into a lowlevel/
machine-level executable program, and the process is called compiling. It translate the
whole program first, then execute the object program.
Example: the equivalent HLL for above ML program
c=a+b
Interpreter is translator program which execute high-level program directly without
compiling it first. High-level languages are more English-like, easier to code, more costly
to run, less flexible. e.g.,
FORTRAN, BASIC, COBOL, PL/1, ALGOL, APL, Pascal, SIMSCRIPT, Smalltalk, C,
C++, Java
Algorithm
A typical programming task can be divided into two phases:
Problem solving phase
 Produce an order of sequence of steps that describe solution of the problem
 This sequence of steps is called an algorithm(pseudocode and flow chart)
Implementation phase
 Implement the sequence of steps in some programming language(code)
Steps in problem solving
First produce a general algorithm (one can use pseudocode)
Refine the algorithm successively to get step by step detailed algorithm that is very close to a
(brief pseudocode) computer language.
 Drawing Flow chart
We have said that a computer is an electronic device which accepts an input from the user and process
that input depending some sets of instructions to get an output, so Algorithm is a sequence of activities to
be processed for getting desired output from a given input. Then we can say that:
Getting specified output is essential after algorithm is executed.
One will get output only if algorithm stops after finite time.
Activities in an algorithm to be clearly defined in other words for it has to be clear.
Before writing an algorithm for a problem, one should find out three things
1 input =what is/are the inputs to the algorithm,
2 output = what is/are expected output after running the algorithm
3 process/connection = the process that is followed to reach/get the desired output.
( what is connection between your input and output)
Algorithm can be expressed in two forms either in pseudocode or in flowchart.

Rules for drawing flowchart

a. Every flow chart has a START symbol and a STOP symbol


b. The flow of sequence is generally from the top of the page to the bottom of the page. This
can vary with loops which need to flow back to an entry point.
c. Use arrow-heads on connectors where flow direction may not be obvious.
d. There is only one flow chart per page
e. A page should have a page number and a title
f. A flow chart on one page should not break and jump to another page
g. A flow chart should have no more than around 15 symbols (not including START and STOP)
questions from above short note
1 To perform a particular task, programmer prepares a sequence of instructions,
known as---------------------------
2 define what means syntax and semantics
3 differentiate high level and low level programming language?
4 ---------------------- is translator program that transform high-level program code into a
low level/ machine-level executable program

5----------------------- is translator program which execute high-level program directly


without compiling it first
Example 1: algorithm and Flowchart to find the area of a circle radius r?

Algorithm:
Step1: Start
Step2: insert radius
Step3: calculate Area=radius*radius*3.145
Step4: print Area
Step5: end process

Flowchart:
Example 2: Write an algorithm and draw a flow chart to calculate 24.
Algorithm:
Step1:1 start
Step 2: Input Base (2), Power (4)
Step 3: Product= Base
Step 4: Product = Product * Base
Step 5: Product = Product * Base
Step 6: Product = Product * Base
Step 7: Print Product
Step 8: end process

FLOW CHART:

• Question: What happens if you want to calculate 2 to the power of 1000 (21000)
• Answer: Use a LOOP (repeated execution of the same set of instructions)
Example 3: Write an algorithm and draw a flow chart to calculate Nm using a loop
approach?

Algorithm:

Step1: Start
Step 2: Input Base (N), Power (m)
Step 3: Product = Base
Step 4: Counter = 1
Step 5: While (Counter < Power)
Repeat steps 6 through step 7
Step 6: Product = Product * Base
Step 7: Counter = Counter + 1
Step 8: Print Product step9: End process

Flowchart:
Example 5: write Algorithm and draw Flowchart to find the greater number
between two numbers?

Algorithm

Step1:1 start
Step 2: input two number(x,y)
Step 3: if(x>Y) display step4
Else display step5
Step 4: x is greater than y
Step 5: y is greater than x
Step 6: end process
Flowchart
Example 6: write Algorithm and draw Flowchart to find the greater number
between three numbers?

Algorithm

Step1:1 start
Step 2: input three number(x, y, z)
Step 3: if(x>y) go to step4
Else go to step 5
Step 4: else-if(x>z) display step6
Else display step 7
Step 5: else-if(y>z) display step8
Else display step9
Step 6: x is greater than all
Step7: z is greater than all
Step8: y is greater than all
Step9: z is greater than all
Step10: end process

Flowchart:
Example 7: Flowchart to calculate the average from 25 exam scores?
Example8: The algorithm and flowchart sums all the even numbers between 1 and 20
inclusive and then displays the sum.

Algorithm
Step1: start
Step2: sum = 0, count=1
Step3: if (count%2==0) go to and repeat step4and step5
Else go to step6
Step4: sum=sum+count
Step5: count=count+1
Step6: count=count+1 go to step3
Step7: print sum
Step8: end process

Flowchart

You might also like