Block Diagram of Digital computer
A digital computer is considered to be a calculating device that can perform arithmetic
operations at enormous speed. It is defined as a device that operates upon information/data. To
be able to process data the computer is made of various functional units to perform its specified
task.
Input Unit:
Computers need to receive data and instruction in order to solve any problem. Therefore, we
need to input the data and instructions into the computers. The input unit consists of one or
more input devices. Keyboard is the one of the most commonly used input device. Other
commonly used input devices are the Mouse, Scanner, Microphone etc. All the input devices
perform the following functions.
• Accept the data and instructions from the outside world.
• Convert it to a form that the computer can understand.
• Supply the converted data to the computer system for further processing.
Storage Unit:
The storage unit of the computer holds data and instructions that are entered through the input
unit, before they are processed. It preserves the intermediate and final results before these are
sent to the output devices. It also saves the data for the later use. The various storage devices
of a computer system are divided into two categories.
a) Primary Storage: Stores and provides very fast. This memory is generally used to hold
the program being currently executed in the computer, the data being received from the
1
input unit, the intermediate and final results of the program. The primary memory is
temporary in nature. The data is lost, when the computer is switched off. In order to store
the data permanently, the data has to be transferred to the secondary memory. The cost of
the primary storage is more compared to the secondary storage. Therefore, most computers
have limited primary storage capacity.
b) Secondary Storage: Secondary storage is used like an archive. It stores several programs,
documents, data bases etc. The programs that you run on the computer are first transferred
to the primary memory before it is actually run. Whenever the results are saved, again they
get stored in the secondary memory. The secondary memory is slower and cheaper than the
primary memory. Some of the commonly used secondary memory devices are Hard disk,
CD, etc.,
Memory Size:
All digital computers use the binary system, i.e. 0’s and 1’s. Each character or a number is
represented by an 8-bit code.
The set of 8 bits is called a byte. A character occupies 1-byte space. A numeric occupies 2-byte
space. Byte is the space occupied in the memory.
The size of the primary storage is specified in KB (Kilobytes) or MB (Megabyte). One KB is
equal to 1024 bytes and one MB is equal to 1000KB. The size of the primary storage in a
typical PC usually starts at 16MB. PCs having 32 MB, 48MB, 128 MB, 256MB memory are
quite common.
Output Unit:
The output unit of a computer provides the information and results of a computation to outside
world. Printers, Visual Display Unit (VDU) are the commonly used output devices. Other
commonly used output devices are Speaker, Headphone, Projector etc.
Arithmetic Logical Unit:
All calculations are performed in the Arithmetic Logic Unit (ALU) of the computer. It also
does comparison and takes decision. The ALU can perform basic operations such as addition,
subtraction, multiplication, division, etc and does logic operations viz, >, <, =, ‘etc. Whenever
calculations are required, the control unit transfers the data from storage unit to ALU once the
computations are done, the results are transferred to the storage unit by the control unit and
then it is send to the output unit for displaying results.
Control Unit:
It controls all other units in the computer. The control unit instructs the input unit, where to
store the data after receiving it from the user. It controls the flow of data and instructions from
the storage unit to ALU. It also controls the flow of results from the ALU to the storage unit.
The control unit is generally referred as the central nervous system of the computer that control
and synchronizes its working.
Central Processing Unit:
The Control Unit (CU) and Arithmetic Logic Unit (ALU) of the computer are together known
as the Central Processing Unit (CPU). The CPU is like brain performs the following functions:
• It performs all calculations.
• It takes all decisions.
•It controls all units of the computer.
2
Operating System: “An Operating system is a program that controls the execution of
application programs and acts as an interface between the user of a computer and the computer
hardware.” A more common definition is that the operating system is the one program running at all
times on the computer (usually called the kernel), with all else being applications programs. An
Operating system is concerned with the allocation of resources and services, such as memory,
processors, devices and information. The Operating System correspondingly includes programs to
manage these resources, such as a traffic controller, a scheduler, memory management module, I/O
programs, and a file system.
Functions of an Operating System: Following are some of important functions of an operating
System.
• Memory Management
• Processor Management
• Device Management
• File Management
• Security
• Control over system performance
• Job accounting
• Error detecting aids
• Coordination between other software and users
1) Memory Management: Memory management refers to management of Primary Memory or Main
Memory. Main memory is a large array of words or bytes where each word or byte has its own address.
Main memory provides a fast storage that can be access directly by the CPU. So for a program to be
executed, it must in the main memory. Operating System does the following activities for memory
management.
• Keeps tracks of primary memory i.e. what part of it are in use by whom, what part are not in use.
• In multiprogramming, OS decides which process will get memory when and how much.
• Allocates the memory when the process requests it to do so.
• De-allocates the memory when the process no longer needs it or has been terminated.
2) Processor Management: In multiprogramming environment, OS decides which process gets the
processor when and how much time. This function is called process scheduling. Operating System
does the following activities for processor management.
• Keeps tracks of processor and status of process. Program responsible for this task is known as traffic
controller.
• Allocates the processor (CPU) to a process.
• De-allocates processor when processor is no longer required.
3) Device Management: OS manages device communication via their respective drivers. Operating
System does the following activities for device management.
• Keeps tracks of all devices. Program responsible for this task is known as the I/O controller.
• Decides which process gets the device when and for how much time.
• Allocates the device in the efficient way.
• De-allocates devices.
4)File Management: A file system is normally organized into directories for easy navigation and
usage. These directories may contain files and other directions. Operating System does the following
activities for file management.
• Keeps track of information, location, uses, status etc. The collective facilities are often known as file
system.
• Decides who gets the resources.
• Allocates the resources.
• De-allocates the resources
5)Other Important Activities: Following are some of the important activities that Operating System
does.
• Security -- By means of password and similar other techniques, preventing unauthorized access to
programs and data.
• Control over system performance -- Recording delays between request for a service and response
from the system.
• Job accounting -- Keeping track of time and resources used by various jobs and users.
• Error detecting aids -- Production of dumps, traces, error messages and other debugging and error
detecting aids.
• Coordination between other software and users -- Coordination and assignment of compilers,
interpreters, assemblers and other software to the various users of the computer systems. 2.4 Working
With Windows Operating System
Compiler
A compiler is a program that converts high-level language to machine language.
Syntax errors: A syntax error is an error in the source code of a program. Since computer
programs must follow strict syntax to compile correctly, any aspects of the code that do not
conform to the syntax of the programming language will produce a syntax error. Syntax errors
are small grammatical mistakes, sometimes limited to a single character. For example, a missing
semicolon at the end of a line or an extra bracket at the end of a function may produce a syntax
error, spelling mistakes, missing out quotes, Missing out brackets, Using upper case characters in
key words e.g. IF instead of if etc.
Logic errors: A logic error (or logical error) is a ‘bug’ or mistake in a program’s source code
that results in incorrect or unexpected behavior. It is a type of runtime error that may simply
produce the wrong output or may cause a program to crash while running. Many different types
of programming mistakes can cause logic errors. For example, assigning a value to the wrong
variable may cause a series of unexpected program errors; multiplying two numbers instead of
adding them together may also produce unwanted results.
Interpreter
An interpreter, like a compiler, translates high-level language into low-level machine language.
The difference lies in the way they read the source code or input. A compiler reads the whole
source code at once, creates tokens, checks semantics, generates intermediate code, executes the
whole program and may involve many passes. In contrast, an interpreter reads a statement from
the input, converts it to an intermediate code, executes it, then takes the next statement in
sequence. If an error occurs, an interpreter stops execution and reports it. whereas a compiler
reads the whole program even if it encounters several errors.
Assembler
An assembler translates assembly language programs into machine code. The output of an
assembler is called an object file, which contains a combination of machine instructions as well
as the data required to place these instructions in memory.
Linker
Linker is a computer program that links and merges various object files together in order to make
an executable file. All these files might have been compiled by separate assemblers. The major
task of a linker is to search and locate referenced module/routines in a program and to determine
the memory location where these codes will be loaded, making the program instruction to have
absolute references.
Loader
Loader is a part of operating system and is responsible for loading executable files into memory
and execute them. It calculates the size of a program (instructions and data) and creates memory
space for it. It initializes various registers to initiate execution.
Algorithm & Flowchart Manual
..
ALGORITHM:
The word “algorithm” relates to the name of the mathematician Al-khowarizmi, which means
a procedure or a technique. Software Engineer commonly uses an algorithm for planning
and solving the problems. An algorithm is a sequence of steps to solve a particular problem
or algorithm is an ordered set of unambiguous steps that produces a result and terminates in
a finite time
Algorithm has the following characteristics
• Input: An algorithm may or may not require input
• Output: Each algorithm is expected to produce at least one result
• Definiteness: Each instruction must be clear and unambiguous.
• Finiteness: If the instructions of an algorithm are executed, the algorithm
should terminate after finite number of steps
The algorithm and flowchart include following three types of control structures.
1. Sequence: In the sequence structure, statements are placed one after the other and
the execution takes place starting from up to down.
2. Branching (Selection): 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.
3. Loop (Repetition): The Loop or Repetition allows a statement(s) to be executed
repeatedly based on certain loop condition e.g. WHILE, FOR loops.
Advantages of algorithm
• It is a step-wise representation of a solution to a given problem, which makes it easy
to understand.
• An algorithm uses a definite procedure.
• It is not dependent on any programming language, so it is easy to understand for
anyone even without programming knowledge.
• Every step in an algorithm has its own logical sequence so it is easy to debug.
3 CIC-UHF
Algorithm & Flowchart Manual
HOW TO WRITE ALGORITHMS
Step 1 Define your algorithms input: Many algorithms take in data to be processed, e.g.
to calculate the area of rectangle input may be the rectangle height and rectangle width.
Step 2 Define the variables: Algorithm's variables allow you to use it for more than one
place. We can define two variables for rectangle height and rectangle width as HEIGHT and
WIDTH (or H & W). We should use meaningful variable name e.g. instead of using H & W
use HEIGHT and WIDTH as variable name.
Step 3 Outline the algorithm's operations: Use input variable for computation purpose,
e.g. to find area of rectangle multiply the HEIGHT and WIDTH variable and store the value in
new variable (say) AREA. An algorithm's operations can take the form of multiple steps and
even branch, depending on the value of the input variables.
Step 4 Output the results of your algorithm's operations: In case of area of rectangle
output will be the value stored in variable AREA. if the input variables described a rectangle
with a HEIGHT of 2 and a WIDTH of 3, the algorithm would output the value of 6.
FLOWCHART:
The first design of flowchart goes back to 1945 which was designed by John Von Neumann.
Unlike an algorithm, Flowchart uses different symbols to design a solution to a problem. It is
another commonly used programming tool. By looking at a Flowchartone can understand the
operations and sequence of operations performed in a system. Flowchart is often considered
as a blueprint of a design used for solving a specific problem.
Advantages of flowchart:
• Flowchart is an excellent way of communicating the logic of a program.
• Easy and efficient to analyze problem using flowchart.
• During program development cycle, the flowchart plays the role of a blueprint, which
makes program development process easier.
• 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.
• It is easy to convert the flowchart into any programming language code.
4 CIC-UHF
Algorithm & Flowchart Manual
Flowchart is diagrammatic /Graphical representation of sequence of steps to solve a
problem. To draw a flowchart following standard symbols are use
Symbol Name Symbol function
Used to represent start and
Oval end of flowchart
Used for input and output
Parallelogram
operation
Processing: Used for
Rectangle arithmetic operations and
data-manipulations
Decision making. Used to
represent the operation in
Diamond which there are two/three
alternatives, true and false
etc
Flow line Used to indicate
Arrows the flow of logic by
connecting symbols
Circle Page Connector
Off Page Connector
Predefined Process
/Function Used to represent
a group of statements
performing one processing
task.
Preprocessor
|--------------
--------- | Comments
|--------------
5 CIC-UHF
Algorithm & Flowchart Manual
..
Algorithm & Flowchart to find Simple Interest
P : Principle Amount
N : Time in Years
R : % Annual Rate of Interest
SI : Simple Interest
Algorithm
Step-1 Start
Step-2 Input value of P, N, R
Step-3 SI = (P x N x R)/100.0
Step-4 Display SI F
Step-6 Stop
Algorithm & Flowchart to find Compound Interest
P : Principle Amount
N : Time in Years
R : % Annual Rate of Interest
CI : Compound Interest
Algorithm
Step-1 Start
Step-2 Input value of P, N, R C
Step-3 CI = P(1+R/100)N - P
Step-4 Display CI
Step-6 Stop
..
12 CIC-UHF
Algorithm & Flowchart Manual
..
Algorithm & Flowchart to Swap Two Numbers using Temporary Variable
Algorithm
Step-1 Start
Step-2 Input Two Numbers Say NUM1,NUM2
Step-3 Display Before Swap Values NUM1, NUM2
Step-4 TEMP = NUM1
Step-5 NUM1 = NUM2
Step-6 NUM2 = NUM1
Step-7 Display After Swap Values NUM1,NUM
Step-8 Stop
Algorithm & Flowchart to Swap Two Numbers without using temporary
variable
Algorithm
Step-1 Start
Step-2 Input Two Numbers Say A,B
Step-3 Display Before Swap Values A, B
Step-4 A=A+B
Step-5 B=A-B
Step-6 A=A-B
Step-7 Display After Swap Values A, B
Step-8 Stop
13 CIC-UHF
Algorithm & Flowchart Manual
..
Algorithm & Flowchart to find the smallest of two numbers
Algorithm
Step-1 Start
Step-2 Input two numbers say
NUM1,NUM2
Step-3 IF NUM1 < NUM2 THEN
print smallest is NUM1
ELSE
print smallest is NUM2
ENDIF
Step-4 Stop
Algorithm & Flowchart to find the largest of two numbers
Algorithm
Start
Step-1 Start
Step-2 Input two numbers say
I nput V alue
NUM1,NUM2 of NUM1
Step-3 IF NUM1 > NUM2 THEN
print largest is NUM1 Input Value
of NUM2
ELSE
print largest is NUM2 Print Yes if No Print
Largest is NUM1 > NUM2
Largest is
NUM1 NUM2
ENDIF
Step-4 Stop
Stop
14 CIC-UHF
Algorithm & Flowchart Manual
..
Algorithm & Flowchart to find the largest of three numbers
Algorithm
Step-1 Start
Step-2 Read three numbers say num1,num2, num3
Step-3 if num1>num2 then go to step-5
Step-4 IF num2>num3 THEN
print num2 is largest
ELSE
print num3 is largest
ENDIF
GO TO Step-6
Step-5 IF num1>num3 THEN
print num1 is largest
ELSE
print num3 is largest
ENDIF
Step-6 Stop
15 CIC-UHF
Algorithm & Flowchart Manual
..
Algorithm & Flowchart to find Even number between 1 to 50
Algorithm
Step-1 Start
Step-2 I=1
Step-3 IF (I >50) THEN
GO TO Step-7
ENDIF
Step-4 IF ( (I % 2) =0) THEN
Display I
ENDIF
Step-5 I=I+1
Step-6 GO TO Step--3
Step-7 Stop
Algorithm & Flowchart to find Odd numbers between 1 to n where n is a
positive Integer
Algorithm
Step-1 Start
Step-2 Input Value of N
Step-3 I=1
Step-4 IF (I >N) THEN
GO TO Step-8
ENDIF
Step-5 IF ( (I % 2)=1) THEN
Display I
ENDIF
Step-6 I=I+1
Step-7 GO TO Step-4
Step-8 Stop
17 CIC-UHF
Algorithm & Flowchart Manual
..
Algorithm & Flowchart to find sum of series 1+2+3+…..+N
Algorithm
Step-1 Start
Step-2 Input Value of N
Step-3 I = 1, SUM=0
Step-4 IF (I >N) THEN
GO TO Step-8
ENDIF
Step-5 SUM = SUM + I
Step-6 I=I+1
Step-7 Go to step-4
Step-8 Display value of SUM
Step-9 Stop
Algorithm & Flowchart to find sum of series 1+3+5+…..+N, Where N is positive
odd Integer
Algorithm
Algorithm
Step-1 Start
Step-2 Input Value of N
Step-3 I = 1, SUM=0
Step-4 IF (I >N) THEN
GO TO step 8
ENDIF
Step-5 SUM = SUM + I
Step-6 I=I+2
Step-7 Go to step-4
Step-8 Display value of SUM
Step-9 Stop
18 CIC-UHF
Algorithm & Flowchart Manual
..
Algorithm & Flowchart to find sum of series 1 – X + X2 –X3 ….XN
Algorithm
Step-1 Start
Step-2 Input Value of N, X
Step-3 I = 1, SUM=1, TERM=1
Step-4 IF (I >N) THEN
GO TO Step-9
ENDIF
Step-5 TERM = - TERM * X
Step-6 SUM = SUM + TERM
Step-7 I=I+1
Step-8 Go to step-4
Step-9 Display value of SUM
Step-10 Stop
Algorithm & Flowchart to print multiplication Table of a number
Algorithm
Step-1 Start
Step-2 Input Value of NUM
Step-3 I=1
Step-4 IF (I >10) THEN
GO TO Step 9
ENDIF
Step-5 PROD = NUM * I
Step-6 WRITE I “x” NUM “=” PROD
Step-7 I=I+1
Step-8 Go to step-4
Step-9 Stop
19 CIC-UHF
Algorithm & Flowchart Manual
..
Algorithm & Flowchart to generate first n Fibonacci terms 0,1,1,2,3,5…n (n>2)
Algorithm
Step-1 Start
Step-2 Input Value of N
Step-3 A=0, B=1, COUNT=2
Step-4 WRITE A, B
Step-5 IF (COUNT >N) then go to step 12
Step-6 NEXT= A + B
Step-7 WRITE NEXT
Step-8 A=B
Step-9 B=NEXT
Step-10 COUNT=COUNT + 1
Step-11 Go to step-4
Step-12 Stop
20 CIC-UHF
Algorithm & Flowchart Manual
..
Algorithm & Flowchart to find Roots of Quadratic Equations AX2+BX+C=0
Algorithm
Step-1 Start
Step-2 Input A,B,C
Step-3 DISC= B2 – 4 A * C
Step-4 IF (DISC < 0) THEN
Write Roots are Imaginary
Stop
ENDIF
Step-5 IF (DISC==0) THEN
Write Roots are Real and Equal
X1 = - B/(2*A)
Write Roots are X1,X1
Stop
ENDIF
Step-6 IF (DISC >0)
Write Roots are Real and Unequal
X1= (- B + SQRT(DISC)) / (2*A)
X2= (- B + SQRT(DISC)) / (2*A)
Write Roots are X1,X2
Stop
ENDIF
22 CIC-UHF
Algorithm & Flowchart Manual
..
Algorithm & Flowchart to find if a number is prime or not
Algorithm
Step-1 Start
Step-2 Input NUM
Step-3 R=SQRT(NUM)
Step-4 I=2
Step-5 IF ( I > R) THEN
Write NUM is Prime Number
Stop
ENDIF
Step 6 IF ( NUM % I ==0) THEN
Write NUM is Not Prime
Stop
ENDIF
Step-7 I=I+1
Step-8 Go to Step-5
23 CIC-UHF
Algorithm & Flowchart Manual
…
Algorithm & Flowchart to find Factorial of number n ( n!=1x2x3x…n)
Algorithm
Step-1 Start
Step-2 Read number N
Step-3 FACT=1 CTRL=1
Step-4 WHILE (CTRL <= N)
DO
FACT=FACT*I
CTRL=CTRL+1
DONE
Step-5 Display FACT
Step-6 Stop
Algorithm & Flowchart to find all the divisor of a number
Algorithm
Step-1 Start
Step-2 Read number N
Step-3 D=1
Step-4 WHILE (D< N)
DO
IF ( N % D ==0) THEN
PRINT D
ENDIF
D=D+1
DONE
Step-5 Stop
25 CIC-UHF