Department of
Computer Engineering
Prof. Twinkle Bhimani
Computer
Programming-
01CE1101
Unit-1
Introduction
What is
Computer…?
A Computer is Electronic device
that can
accept data,
store data,
retrieve the stored data
process data as desired
and when required
output the result in
desired format.
Hardware and Software
What is
Hardware?
▪Hardware refers to the physical parts of a computer.
▪The term hardware also refers to mechanical device that
makes up computer.
▪User can see and touch the hardware components.
▪Examples of hardware are CPU, keyboard, mouse, hard
disk, etc...
What is
Software?
▪A Computer software is a set of instructions for a
computer to perform a specific task.
What is
Computer
Software?
▪A set of instruction in a logical order to perform a meaningful
task is called program and a set of program is called software.
▪It tell the hardware how to perform a task.
▪Types of software
System software
It is designed to operate the computer hardware efficiently.
Provides and maintains a platform for running application
software.
Examples: Windows, Linux, Unix etc.
Application software
It is designed to help the user to perform general task such
as word processing, web browser etc.
Primarily concerned with solution of some problem using
computer as a tool.
Examples: Microsoft Word, Excel, PowerPoint etc.
Block Diagram
of Computer
Block Diagram
of Computer
Central Processing Unit
Input Section
(Keyboard, Mouse,
Scanner, etc.)
Output Section
(Monitor, Printer,
etc.)
Control Unit (CU)
Arithmetic Logic
Unit (ALU)
Primary Memory
(RAM, ROM, etc.)
Secondary Memory
(Hard disk, Pen drive, etc.)
RAM
▪RAM stands for Random Access Memory, and it's one of
the most fundamental elements of computing.
▪It holds data till the power is on.
▪The data is lost as the power supply is cut off, so it is
called volatile memory.
▪RAM isa temporary memory bank where your computer
stores data it needs to retrieve quickly.
▪RAM is essentiallyshort term memory where data is
stored as the processor needs it.
▪This isn't to be confused with long-term data that's
stored on your hard drive, which stays there even when
your computer is turned off.
ROM
▪It stands for Read Only Memory
▪It holds data permanently. So, It is called non-volatile
memory.
▪It's used to store the start-up instructions for a computer,
also known as the firmware.
▪Ordinary use can not store information in ROM, Only
manufacturers of ROM Chip can store the data.
▪This means it receives data and permanently writes it on
a chip, and it lasts even after you turn off your computer.
▪ The data is coded to not be overwritten, so it's used for
things like your printer software or your startup
programs.
RAM vs ROM
RAM ROM
RAM is a volatile memory which
could store the data as long as the
power is supplied.
ROM is a non-volatile memory
which could retain the data even
when power is turned off.
Data stored in RAM can be
retrieved and altered.
Data stored in ROM can only be
read
Used to store the data that has to
be currently processed by CPU
temporarily.
It stores the instructions required
during bootstrap of the computer.
It is a high-speed memory. It is much slower than the RAM
Costlier cheaper than RAM
A RAM chip can store only a few
gigabytes (GB) of data.
A ROM chip can store multiple
megabytes (MB) of data
Application of
Computer
▪Entertainment
▪Communication
▪Text (word) Processing
▪Image Processing
▪Voice Recognition
▪Numerical and Data Processing
Types of
Computer
Languages
▪Low level language
▪Assembly language
▪High level language
Types of
Computer
Languages
Machine language OR Low level language
It is language of 0’s and 1's (i.e. Binary form)
Computer directly understand this language.
▪Computers are made of many tiny switches that can be
either on or off. When a switch is on, it is represented by
a 1. When it is off, it is represented by a 0.
These 1s and 0s are calledbits. Bits are the fundamental
language of nearly all computers and every program must
be translated into bits before it can be executed by the
computer.
▪
Types of
Computer
Languages
Assembly language
▪It uses short descriptive words (MNEMONIC) to
represent each of the machine language instructions.
▪This reduce coding time and the amount of information
the programmer has to remember.
▪It requires a translator known as assembler to convert
assembly language into machine language so that it can
be understood by the computer.
▪Examples: 8085 Instruction set
MOV R0,A
ADD R0,R1
Types of
Computer
Languages
High level language
▪It is a machine independent language.
▪We can write programs in English like manner and
therefore easier to learn and use.
▪High level language is designed to be user friendly,
enabling programmers to write instruction using a
combination of words in English and in mathematical
notations.
▪Examples: C, C++, JAVA etc...
Compiler,
Interpreter &
Assembler
▪Compiler translates program of high level language to
machine language. It converts whole program at a time.
▪Interpreter translates program of high level language to
machine language. It converts program line by line.
▪Assembler translates program of assembly language to
machine language.
Common
Number
Systems
System Base Symbols Used by
Humans?
Used in
Computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa-
decimal
16 0, 1, … 9,
A, B, … F
No No
(157.63)
10
▪To convert decimal number 157.63, we convert its
integer and fraction part individually and then add them
to get the equivalent binary number, as below:
▪To convert integer 157 to binary, follow these steps:
▪Divide 157 by 2 keeping notice of the quotient and the
remainder. Continue dividing the quotient by 2 until you
get a quotient of zero.
▪Then just write out the remainders in the reverse order
to get the equivalent binary number.
Continue..
▪157 / 2 = 78 with remainder 1
78 / 2 = 39 with remainder 0
39 / 2 = 19 with remainder 1
19 / 2 = 9 with remainder 1
9 / 2 = 4 with remainder 1
4 / 2 = 2 with remainder 0
2 / 2 = 1 with remainder 0
1 / 2 = 0 with remainder 1
▪Here is the answer to 157 decimal to binary number:
10011101
Continue…
▪For converting decimal fraction 0.63 to binary number,
follow these steps:
▪Multiply 0.63 by 2 keeping notice of the resulting integer
and fractional part. Continue multiplying by 2 until you
get a resulting fractional part equal to zero (we calculate
up to ten digits).
▪Then just write out the integer parts from the results of
each multiplication to get equivalent binary number.
Binary to
Decimal
▪Technique
Multiply each bit by 2
n
, where n is the “weight” of the bit
The weight is the position of the bit, starting from 0 on
the right
Add the results
Binary Decimal
Example
(Binary to
Decimal)
1 0 1 0 1 1
1 x 2
0
1 x 2
1
0 x 2
2
1 x 2
3
0 x 2
4
1 x 2
5 +++++
120
101011
2 =
032 +++++
43
10
43
10
8
Example
(Binary to
Decimal)
1 1 . 1 1
1 x 2
0
1 x 2
1+
12
11.11
2 =
+
3.75
10
3.75
10
1 x 2
-2
1 x 2
-1+
0.250.5+
+
+
Algorithm
▪An Algorithm is a finite sequence of well defined steps for
solving a problem in systematic manner.
▪It is written in the natural languages like English.
▪Advantages
Easy to write.
Human readable techniques to understand logic.
Algorithms for big problems can be written with
moderate efforts.
▪Disadvantages
Difficult to debug.
Difficult to show branching and looping.
Jumping (goto) makes it hard to trace some problems.
Example of
Algorithm
▪Write an algorithm to find whether given number is even
or odd.
Step 1 : Input no.
Step 2 : If no mod 2=0, goto 4.
Step 3 : Print given no is odd, goto 5.
Step 4 : Print given no is even.
Step 5 : Stop.
Flowchart
▪Flowchart is a pictorial or graphical representation of a
process.
▪Each step in the process is represented by a different
symbol and contains a short description of the process
step.
▪The flowchart symbols are linked together with arrows
showing the process flow direction.
▪This pictorial representation can give step-by-step
solution of the given problem.
Flowchart
▪Advantages
Easy to draw
Easy to understand logic
Easy to identify mistakes by non computer person
Easy to show branching and looping
▪Disadvantages
Time consuming
Difficult to modify
Very difficult to draw flowchart for big or complex
problems
Flowchart
Symbols
Start / Stop
Process
Subroutine
Input / Output
Decision Making
Arrows
Example of
Flowchart
▪Draw a flowchart to find average of three numbers
entered by the user.
Start
Read n1,n2,n3
PRINT Average
Stop
Average = (n1+n2+n3) / 3
Example of
Flowchart
▪Draw a flowchart to find whether given number is even
or odd.
Start
Read no
Is no mod
2 = 0?
Print no
is even
Print no
is odd
Stop
Yes No
Example
▪Write an algorithm to enter number still user wants and
at the end it should display count of total number of
positive, negative and zero entered.
1.Initialize pos=0, neg=0, zero=0
2.Read no
3.If no Greater than 0, pos = pos + 1, goto 6
4.If no Less than 0, neg = neg + 1, goto 6
5.zero=zero+1
6.Print “Do you want to enter more number?”
7.Read ans
8.If ans = “y”, goto 2
9.Print pos, neg, zero
10.Stop
Example of
Flowchart
Start
Read no
no>0?
Stop
Yes No
pos =0, neg=0, zero=0
pos = pos + 1
Do you want to
enter more
number?
Yes
no<0?
Yes
neg = neg + 1 zero = zero + 1
No
Print pos, neg, zero
No
Questions
1.List out the symbol names used in flowchart.
2.Write the steps to convert Decimal to Binary, Binary to
Decimal and explain with example.
3.Differentiate the RAM and ROM
4.Explain flowchart with an example
5.Which is output device? (a) Barcode Reader (b)
Scanner (c) LCD (d) Keypad
6.What is Volatile Memory?
7.Define High level, Assembly and low level language.