ES105-Programming For Problem Solving: Chapter - 1
ES105-Programming For Problem Solving: Chapter - 1
Problem Solving
Chapter - 1
• Computer What is Computer?
– Device capable of performing computations and making
logical decisions
– Computers process data under the control of sets of
instructions called computer programs
• Hardware
– Physical components of computer
– Various devices comprising a computer
– Keyboard, screen, mouse, disks, memory, CD-ROM, and
processing units
• Software
– Programs or set of instructions that run on a computer
Computer
• Input Unit − Devices like keyboard and mouse that are used to input data and instructions to
the computer are called input unit.
• Output Unit − Devices like printer and visual display unit that are used to provide information
to the user in desired format are called output unit.
• Control Unit − As the name suggests, this unit controls all the functions of the computer. All
devices or parts of computer interact through the control unit.
• Arithmetic Logic Unit − This is the brain of the computer where all arithmetic operations and
logical operations take place.
• Memory − All input data, instructions and data interim to the processes are stored in the
memory. Memory is of two types – primary memory and secondary memory. Primary
memory resides within the CPU whereas secondary memory is external to it.
• CPU − Control unit, arithmetic logic unit and memory are together called the central processing
unit or CPU.
Primary Memory
• Primary memory holds only those data and instructions on which the computer is currently
working.
• It has a limited capacity and data is lost when power is switched off.
• These memories are faster than secondary memory because it requires less overhead.
• Also known as Main Memory and is volatile
• The data and instruction required to be processed resides in the main memory. It is divided
into two subcategories RAM and ROM.
• RAM(Random Access Memory): internal memory of the CPU for storing data, program, and
program result. It is a read/write memory which stores data until the machine is working.
• ROM(Read Only Memory): The memory from which we can only read but cannot write on it.
The information is stored permanently in such memories during manufacture. A ROM stores
such instructions that are required to start a computer.
Secondary Memory
• Step1: Start
• Step2: Read\input the first num1.
• Step3: Read\input the second num2.
• Step4: Sum <- num1+num2 // calculation of sum
• Step5: Print Sum
• Step6: End
Algorithm - Example
• Step1: Start
• Step2: Read\input the first num1.
• Step3: Power <- num1^2 // power of 2
• Step4: Print Sum
• Step5: End
Flowchart
• Advantages:
1. Flowchart is an excellent way of communicating the logic of a program.
2. Easy and efficient to analyze problem using flowchart.
3. During program development cycle, the flowchart plays the role of a blueprint, which
makes program development process easier.
4. After successful development of a program, it needs continuous timely maintenance during
the course of its operation. The flowchart makes program or system maintenance easier.
5. It is easy to convert the flowchart into any programming language code.
Flowchart
Flowchart - Example
Pseudocode
• An alternative approach to express an algorithm that bridges the gap between flowcharts
and computer code is called pseudocode.
• This technique uses code-like statements in place of the graphical symbols of the flowchart.
• Ex. . Keywords such as IF, DO, INPUT, etc., are capitalized, whereas the conditions,
processing steps, and tasks are in lowercase. Additionally, the processing steps are
indented.
• One advantage of pseudocode is that it is easier to develop a program with it than with a
flowchart.
Logical Representations - Sequence
• Selection provides a means to split the program’s flow into branches based
on the outcome of a logical condition.
• In branch control, there is a condition and according to a condition, a
decision of either TRUE or FALSE is achieved.
• In the case of TRUE, one of the two branches is explored; but in the case of
FALSE condition, the other alternative is taken. Generally, the
• ‘IF-THEN’ is used to represent branch control.
Logical Representations - Selection
Logical Representations - Selection
Logical Representations - Repetition
1. Step-1 Start
2. Step-2 Input Side Length of Square say L
3. Step-3 Area = L x L
4. Step-4 PERIMETER = 4 x L
5. Step-5 Display AREA, PERIMETER
6. Step-6 Stop
Example – Find the largest of two numbers
1. Step-1 Start
2. Step-2 Input two numbers say
NUM1,NUM2
3. Step-3 IF NUM1 > NUM2 THEN
print largest is NUM1
ELSE
print largest is NUM2
ENDIF
4. Step-4 Stop
Example – Find even number between 1 to 50
1. Step-1 Start
2. Step-2 I = 1
3. Step-3 IF (I >50) THEN
GO TO Step-7
ENDIF
4. Step-4 IF ( (I % 2) =0) THEN
Display I
ENDIF
5. Step-5 I = I + 1
6. Step-6 GO TO Step--3
7. Step-7 Stop
Exercise