1. Unit – 2 Programming Concept
Introduction:
To interact with a person, we need to speak the language that he or
she can understand. Similarly, to interact with computer we need a
computer language that a computer can understand because
computer can understand only 0s and 1s. a computer language
provides a way of giving instructions to the computer.
What is a Program?
A program is a set of instructions written in a computer language
that directs the computer to perform a particular task and produce
the desired result. In order to perform the task, the program gives
these instructions to the computer.
1) Read Input
2) Process Data
3) Store Data
4) Write Output
However, before writing a program it is important to understand
the task and identify the various inputs required to produce the
output. For this the task is broken down into simple steps. This can
be accomplished by using three tools:
1) Algorithm
2) Flowchart
3) Pseudo code
2. Algorithm
An algorithm is the first step in developing a program. When we
tell the computer what to do, we also need to specify how it is
going to do it. For this, algorithms are required. An Algorithm can
be defined as a finite sequence of instructions for solving a
problem.
Example 1: Algorithm to go to School.
Step 1: Wake up early in the morning.
Step 2: Dress up for your school.
Step 3: Pack your school bag.
Step 4: Have your breakfast.
Step 5: Board your school bus.
Example 2: Algorithm to add two numbers.
Step 1: Take two numbers as inputs, say A and B.
Step 2: Add A and B and store the result in C.
Step 3: display the value of C.
Flowchart:
On the basis of Algorithm, we make Flowcharts. A Flowchart is a
pictorial representation of an algorithm. A flowchart makes it
easier to understand the logic of a program. In a flowchart,
different symbols are used for different instructions. The different
symbols and their descriptions are listed in the table.
Name Symbol Description
Start/ Stop Box Used to indicate the start and
the end of the flowchart.
3. Input/ Output Box Used to accept the input and
deliver the output.
Process Box Used for Processing.
Decision Box Used when the condition of
‘Yes’ or ‘No’ arises.
Flow Lines Used to show the flow of
control in the flowchart.
Guidelines for preparing Flowchart:
1) A flowchart should be neat, clear and easy to follow.
2) There should be only one start box and stop box.
3) Only one flow line should be used with the start or the
stop box.
4) Only one flow line should come out from a process box.
5) Only one flow line should enter the decision box.
Example 1: A flowchart to add two numbers.
4. Example 2: A flowchart to find greater number.
Example 3: A flowchart to go to school.
5. Loops:
Sometimes, you need to repeat a set of statements a number of
times. Instead of writing the statements again and again, you can
direct the flow lines back to a previous statement in the flowchart.
Such a sequence of statements which is repeated again and again is
said to be in a Loop.
Example: Check whether entered number is 55 or not?
6. Pseudo code:
A Pseudo Code is English– like representation of the program,
which is independent of any computer language. It is an outline or
a program that can be easily converted into program instructions in
a specific programming language. Pseudo code uses some
keywords to denote programming processes. These are some of
them-
1) Input: READ, OBTAIN, GET and PROMPT
2) Output: PRINT, DISPLAY and SHOW
3) Compute: COMPUTE, CALCULATE, DETERMINE,
ADD, SUBTRACT, MULTIPLY and DIVIDE
4) Initialize: SET and INITIALIZE
5) Add One: INCREMENT
Example 1: To add two numbers.
Step 1: READ number1 and number2.
Step 2: ADD number1and number2.
Step 3: PRINT total.
Example 2: To calculate the average marks of a student.
Step 1: READ total marks.
Step 2: DIVIDE total marks by the number of subjects.
Step 3: STORE the result in average.
Step 4: PRINT average.