Module 1 Its Lecture Notes
Module 1 Its Lecture Notes
EST102 Programming in C
Module I
Basics of Computer Hardware and Software, Basics of Computer Architecture: processor, Memory, Input& Output
devices. Application Software & System software: Compilers, interpreters, High level and low level languages
Introduction to structured approach to programming, Flow chart , Algorithms, Pseudo code (bubble sort, linear
search - algorithms and pseudocode)
Computer Architecture
The basic components of a modern digital computer are: Input Device, Output Device, Central
Processing Unit (CPU), and memory.
Central Processing Unit (CPU)
CPU is the brain of the computer system. All major calculation and comparisons are made
inside the CPU and it is also responsible for activation and controlling the operation of other
units. This unit consists of two major components that are arithmetic logic unit (ALU) and
control unit (CU).
EST102 Programming in C
It also controls all devices such as memory, input/output devices connected to the CPU.
Additionally, CPU also has a set of registers for temporary storage of data, instructions,
addresses and intermediate results of calculation
When the ALU, CU and the registers are all integrated on a single chip, it is called a
microprocessor thereby capturing the entire CPU on a single chip
Memory Unit
The Memory unit refers to the area where instructions and data are stored in a
computer. The processor reads instructions and data from the memory, executes them and
writes the result back to it. Different forms of memory are used in a computer system.
They vary in their size, speed and location. Anything and everything in a computer is
stored in the form of bits known as binary language or machine language. 8 bits make up a
byte. The total number of bytes that a memory chip can hold at a time is termed as its size
or capacity. Information is stored and processed as a group of bytes, called computer word.
The word length is specific for each processor.
The Registers - Since the group of registers is in-built within the processor chip, they
are the fastest accessible units of memory by the processor. They are highly expensive
and hence are limited in number. Some registers are used to store data while some are
reserved to store address. There are some general purpose registers as well. Size of the
registers depends on the processor. Accumulator is a register found on all processors,
which is mainly used to store the operand of an arithmetic operation. Program
IIPE 2
EST102 Programming in C
counter (PC) always stores the address of the next instruction to be executed by the
processor.
The Cache Memory: - It is a small piece of high speed volatile memory located closer
to the processor for fast processing. Cache memory is made of high speed SRAMs. It
acts as a buffer between the CPU and the RAM. It holds frequently accessed data and
instructions so that they can be easily supplied to the CPU when requested again. Cache
memory is used to reduce the average time to access data from the Main memory.
Primary Memory: - The memory chips that the processor can directly access are
referred to as primary memory. The three types of primary memory are RAM, ROM and
CMOS. RAM is volatile whereas ROM as CMOS are non-volatile memories. They are
metal oxide semiconductor memory cells built on silicon based ICs.
Random Access Memory (RAM): RAM is a volatile memory and loses its contents
when the power is turned off. The circuit is so designed that any random location can
be directly accessed without the need to scroll up or down the memory. The program to
be executed is loaded into RAM from the non-volatile backup memory. The processor
reads instructions and data from the RAM, executes them and writes data back to the
RAM. Hence RAM is also known as the main memory of the computer. Everything from
the RAM is copied to the non-volatile backup memory before the computer is turned
off. The two main types of RAM are Dynamic Ram (DRAM) and static RAM (SRAM).
Each memory cell in a DRAM is made of one transistor and one MOS capacitor, which
store one bit of data. However, this cell starts losing its charge and hence data can be
retained for less than thousandth of a second. So it needs to be refreshed thousand times a
second, which takes up processor time. However, due to small size of each cell, one DRAM
can have large number of cells. Primary memory of most of the personal computers is
made of DRAM.
Each cell in SRAM is made of several transistors in a cross coupled flip flop
configuration that stores one bit. It retains its bit till the power supply is on and doesn9t
need to be refreshed like DRAM. It also has shorter read-write cycles as compared to
DRAM. SRAM is used in specialized applications.
IIPE 3
EST102 Programming in C
Read Only Memory (ROM): ROM is a non-volatile memory and hence retains its contents
even when the computer is switched off. It is used for storing software that is rarely
changed during the life of the system, sometimes known as firmware. Almost every
computer comes with a small amount of ROM containing the boot firmware which is
essential for the boot-up. BIOS is a firmware used to perform hardware initialization
during the booting process and to provide runtime services for operating systems and
programs. The BIOS firmware comes pre-installed on the ROM and it is the first software
to run when the computer is powered on. ROM memories have gradually evolved from
fixed read-only memories to memories that can be programmed and then re-programmed.
Secondary Memory: - Primary memory has limited storage capacity and is volatile.
Secondary memory overcomes this limitation by providing permanent storage of data and
in bulk quantity. They are the slowest and cheapest form of memory. It cannot be accessed
directly by the CPU. Programs need to be moved to primary memory in order to be
executed by the CPU. Secondary memory is also termed as external memory and refers to
the various storage media on which a computer can store data and programs.
The secondary storage media can be fixed or removable. Fixed storage media is an
internal storage medium like hard disk that is fixed inside the computer. Fixed storage
IIPE 4
EST102 Programming in C
devices are literally not fixed; obviously these can be removed from the system for
repairing work, maintenance purpose, and also for upgrade etc. Technically, almost all of
the data i.e. being processed on a computer system is stored on some type of a built-in
fixed storage device. Storage medium that are portable and can be taken outside the
computer are termed as removable storage media.
Magnetic Storage Media: Magnetic media is coated with a magnetic layer which is
magnetized in clockwise or anticlockwise directions. When the disk moves, the head
interprets the data stored at a specific location in binary 1s and 0s at reading. Examples:
hard disks, floppy disks and magnetic tapes.
Floppy Disk: A floppy disk is a flexible disk with a magnetic coating on it. It is packaged
inside a protective plastic envelope. These are one of the oldest types of portable storage
devices that could store up to 1.44 MB of data but now they are not used due to very less
memory storage.
Hard disk: A hard disk consists of one or more circular disks called platters which are
mounted on a common spindle. Each surface of a platter is coated with a magnetic
material. Both surfaces of each disk are capable of storing data except the top and bottom
disk where only the inner surface is used. The information is recorded on the surface of the
rotating disk by magnetic read/write heads. These heads are joined to a common arm
known as access arm.
Optical Storage Media: In optical storage media information is stored and read using a
laser beam. The data is stored as a spiral pattern of pits and ridges denoting binary 0 and
binary 1. Examples: CDs and DVDs
Compact Disk: A Compact Disc drive (CDD) is a device that a computer uses to read data
that is encoded digitally on a compact disc (CD). A CD drive can be installed inside a
computer9s compartment, provided with an opening for easier disc tray access or it can be
used by a peripheral device connected to one of the ports provided in the computer
system. A compact disk or CD can store approximately 650 to 700 megabytes of data. A
computer should possess a CD Drive to read the CDs.
IIPE 5
EST102 Programming in C
DVD: It stands for Digital Versatile Disk or Digital Video Disk. It looks just like a CD and use
a similar technology as that of the CDs but allows tracks to be spaced closely enough to
store data that is more than six times the CD9s capacity. It is a significant advancement in
portable storage technology. A DVD holds 4.7 GB to 17 GB of data.
Blue Ray Disk: This is the latest optical storage media to store high definition audio and
video. It is similar to a CD or DVD but can store up to 27 GB of data on a single layer disk
and up to 54 GB of data on a dual layer disk. While CDs or DVDs use red laser beam, the
blue ray disk uses a blue laser to read/write data on a disk
Solid State Memories: Solid-state storage devices are based on electronic circuits with no
moving parts like the reels of tape, spinning discs etc. Solid-state storage devices use
special memories called flash memory to store data. Solid state drive (or flash memory) is
used mainly in digital cameras, pen drives or USB flash drives.
Pen Drives: Pen Drives or Flash drives are the recently emerged portable storage media. It
is an EEPROM based flash memory which can be repeatedly erased and written using
electric signals. This memory is accompanied with a USB connector which enables the pen
drive to connect to the computer. They have a capacity smaller than a hard disk but greater
than a CD.
IIPE 6
EST102 Programming in C
HARDWARE
Hardware consists of the mechanical parts that make up the computer as a machine. The
hardware consists of physical devices of the computer. The devices are required for input,
output, storage and processing of the data.
Keyboard, monitor, hard disk drive, floppy disk drive, printer, processor and motherboard are
some of the hardware devices.
SOFTWARE
Software is a set of instructions that tells the computer about the tasks to be performed
and how these tasks are to be performed. Program is a set of instructions, written in a language
understood by the computer, to perform a specific task. A set of programs and documents are
collectively called software.
Software is classified into two categories
System Software
Application Software
SYSTEM SOFTWARE
System Software is the type of software which is the interface between application
software and computer hardware. Low level languages are used to write the system
software. System Software maintains the system resources and give the path for application
software to run. An important thing is that without system software, system cannot run. It
is a general purpose software.
Operating System
IIPE 7
EST102 Programming in C
Examples: Microsoft Disk Operating System (MS-DOS), Windows 7, Windows XP, Linux, UNIX,
and Mac OS X Snow Leopard.
APPLICATION SOFTWARE
The software that a user uses for accomplishing a specific task is the application
software. Application software may be a single program or a set of programs. It runs on the
platform which is provided by system software. High level languages are used to write the
application software. It is a specific purpose software.
Examples
Word Processing Software: For writing letter, reports, documents etc. (e.g. MS-
WORD).
Image Processing Software: For assisting in drawing and manipulating graphics (e.g.
Adobe Photoshop).
The main difference between System Software and Application Software is that
without system software, system cannot run on the other hand without application
software, system always runs.
IIPE 8
EST102 Programming in C
TYPES OF LANGUAGES
Computer programs can be written in high and low level languages, depending on the
task and the hardware being used.
ASSEMBLY LANGUAGE
A program written in assembly language uses symbolic representation of machine codes
needed to program a particular processor (CPU) or processor family. This representation is
usually defined by the CPU manufacturer, and is based on abbreviations (called mnemonics)
that help the programmer remember individual instructions, registers, etc. Small, English-like
representation is used to write the program in assembly language
Features
Assembly language programs are easier to write than the machine language programs,
since assembly language programs use short, English-like representation of machine
code.
For example
IIPE 9
EST102 Programming in C
ADD 2, 3
LOAD A
SUB A, B
The program written in assembly language is the source code, which has to be converted
into machine code, also called object code, using translator software, namely, assembler.
Each line of the assembly language program is converted into one or more lines of
machine code. Hence assembly language programs are also machine-dependent.
SYSTEM TRANSLATORS
IIPE 10
EST102 Programming in C
INTERPRETER
Interpreter is a translator used to convert high-level programming language to low-level
programming language.
Example: Python, jvm(Java Virtual Machine)
ASSEMBLER
An assembler is a translator used to translate assembly language to machine language.
Example: Fortran Assembly Program (FAP), Macro Assembly Program (MAP)
BASIS FOR
COMPILER INTERPRETER
COMPARISON
Errors Display all errors after Displays error of each line one
compilation, all at the same by one.
time.
IIPE 11
EST102 Programming in C
from one instruction to some other with the help of any statement like GOTO, etc.
Therefore, the instructions in this approach will be executed in a serial and structured
manner. The languages that support structured programming approach are:
C
C++
java
Advantages of Structured Programming Approach
1. Easier to read and understand
2. Easier to Maintain
3. Easier to Debug
4. Machine-Independent, mostly.
ALGORITHM
It is a complete step by step representation of the solution of the problem,
represented in English like Languages. An algorithm can be abstract or quite detailed. A
detailed algorithm consists of every step, equivalent to one instruction of a programming
language.
Examples:
Algorithm to find the area of circle
1. Start
2. Read radius
3. area=3.14*radius*radius
4. Print area
5. Stop
EST102 Programming in C
4. Print Sum
5. Stop
EST102 Programming in C
6. Read Num
7. If Num>Large, then Large=Num
8. Count=Count+1
9. If Count<N-1, then goto step 6
10. Print Large
11. Stop
1. Start
2. Get the total number of elements of the array in variable, 8n9
3. Read the numbers into array a
4. Let i=0
5. Let j=0
6. Compare jth number with the (j+1)th number; if it is greater, swap them
7. Increment j
8. Repeat step 6 & 7 until j= n-i-1
9. Increment i
10. Repeat steps 5 to 9 until i=n-1
11. Print the sorted array
12. Stop
IIPE 14
EST102 Programming in C
11. Stop
FLOWCHART
Start, Stop
Read, Print
Processing Statements
Condition Check
Direction of flow
IIPE 15
EST102 Programming in C
IIPE 16
EST102 Programming in C
IIPE 17
EST102 Programming in C
PSEUDO CODE
It is a more formal representation than the algorithm. Here, we represent every step
in a formal way which is very close to the actual programming language representation. In
pseudocode, each of the steps will be written via operator and statements equivalent to
some programming language instructions. The only difference will be that the exact syntax
of the programming language will not be followed. All pseudocodes will start with the
keyword <START= and complete with keyword <STOP= or <END=.
Example: Pseudocode to find the area of circle
1. START
2. Read radius
3. area = 3.14 * radius * radius
4. print area
5. STOP
SAMPLE QUESTIONS
1. Write short note on processor and memory in a computer. [KTU MODEL 2020]
2. What are the differences between compiled and interpreted languages? Give example for
IIPE 18
EST102 Programming in C
IIPE 19
EST102 Programming in C
JANUARY 2016]
32. Give the algorithm and draw flowchart for generating Armstrong number between the
given ranges. (Armstrong number is a number z such that sum of cubes of the digits of z is
equal to n) [KTU,JANUARY 2017]
33. Draw the flowchart to find out the greatest of three numbers. [KTU, JANUARY 2016]
34. Write the algorithm to perform bubble sorting and illustrate the step by step changes in the
following array of numbers for each iteration.
24 14 36 79 88 12 6
IIPE 20