Module 1
Introduction to C
Introduction to Computers
A computer can be defined as an electronic device ,that
is designed to accept data, perform the required
mathematical and logical operations at high speed,and
output the result.
Characteristics of Computer
Characteristics of Computer
• Speed
• Accuracy
• Automation
• Diligence
• Versatile
• Memory
• No IQ
• Economical
Stored Program Concept
• Before any data is processed, instructions are read into
memory.
• Instructions are stored in the Computer’s memory for
execution.
• Processing starts with first instruction in the program,
which is copied into a control unit circuit.
Types of Stored Program Computers
[Link] Neuman Architecture: Stores data and instructions in
the same memory.
Process Execution becomes slower .
[Link] Program Concept: Separate memory to store data
and instructions.
Types of Stored Program Computers
History of Computers
• 1822: English mathematician Charles Babbage (Father of Computer)
conceives of a steam-driven calculating machine that would be able
to compute tables of numbers.
• 1890: Herman Hollerith designs a punch card system to calculate the
1880 census, accomplishing the task in just three years and saving the
government $5 million. He establishes a company that would
ultimately become IBM.
• 1936: Alan Turing presents the notion of a universal machine, later
called the Turing machine, capable of computing anything that is
computable.
• 1941: Atanasoff and his graduate student, Clifford Berry, design a
computer that can solve 29 equations simultaneously. This marks the
first time a computer is able to store information on its main memory.
Punch Card
• 1943-1944: Two University of Pennsylvania professors, John Mauchly
and J. Presper Eckert, build the Electronic Numerical Integrator and
Calculator (ENIAC). Considered the grandfather of digital computers,
it fills a 20-foot by 40-foot room and has 18,000 vacuum tubes.
• 1946: Mauchly and Presper leave the University of Pennsylvania and
receive funding from the Census Bureau to build the UNIVAC, the first
commercial computer for business and government applications.
• 1947: William Shockley, John Bardeen and Walter Brattain of Bell
Laboratories invent the transistor. They discovered how to make an
electric switch with solid materials and no need for a vacuum.
• 1953: Grace Hopper develops the first computer language, which
eventually becomes known as COBOL. Thomas Johnson Watson Jr.,
son of IBM CEO Thomas Johnson Watson Sr., conceives the IBM 701
EDPM to help the United Nations keep tabs on Korea during the war.
• 1953: Grace Hopper develops the first computer language, which
eventually becomes known as COBOL. Thomas Johnson Watson Jr.,
son of IBM CEO Thomas Johnson Watson Sr., conceives the IBM 701
EDPM to help the United Nations keep tabs on Korea during the war.
• 1958: Jack Kilby and Robert Noyce unveil the integrated circuit,
known as the computer chip. Kilby was awarded the Nobel Prize in
Physics in 2000 for his work.
• 1964: Douglas Engelbart shows a prototype of the modern computer,
with a mouse and a graphical user interface (GUI). This marks the
evolution of the computer from a specialized machine for scientists
and mathematicians to technology that is more accessible to the
general public.
• 1969: A group of developers at Bell Labs produce UNIX, an operating
system that addressed compatibility issues. Written in the C
programming language, UNIX was portable across multiple platforms
and became the operating system of choice among mainframes at
large companies and government entities.
• 1970: The newly formed Intel unveils the Intel 1103, the first Dynamic
Access Memory (DRAM) chip.
• 1971: Alan Shugart leads a team of IBM engineers who invent the
"floppy disk," allowing data to be shared among computers.
• 1973: Robert Metcalfe, a member of the research staff for Xerox,
develops Ethernet for connecting multiple computers and other
hardware.
• 1974-1977: A number of personal computers hit the market,
including Scelbi & Mark-8 Altair, IBM 5100, Radio Shack's TRS-
80 — affectionately known as the "Trash 80" — and the
Commodore PET.
• 1975: The January issue of Popular Electronics magazine
features the Altair 8080, described as the "world's first
minicomputer kit to rival commercial models." Two "computer
geeks," Paul Allen and Bill Gates, offer to write software for the
Altair, using the new Beginners All Purpose Symbolic
Instruction Code (BASIC) language.
• 1981: The first IBM personal computer, code-named "Acorn," is
introduced. It uses Microsoft's MSDOS operating system. It has
an Intel chip, two floppy disks and an optional color monitor. It
also popularizes the term PC.
• 1983: Apple's Lisa is the first personal computer with a graphical
user interface (GUI). It also features a drop-down menu and
icons.
• 1996: Sergey Brin and Larry Page develop the Google search
engine at Stanford University.
• 1999: The term Wi-Fi becomes part of the computing language
and users begin connecting to the Internet without wires.
• 2001: Apple unveils the Mac OS X operating system, which
provides protected memory architecture and pre-emptive
multi-tasking, among other benefits.
• 2003: The first 64-bit processor, AMD's Athlon 64, becomes
available to the consumer market.
• 2004: Mozilla's Firefox 1.0 challenges Microsoft's Internet
Explorer, the dominant Web browser. Facebook, a social
networking site, launches.
• 2005: YouTube, a video sharing service, is founded. Google
acquires Android, a Linux-based mobile phone operating
system.
• 2006: Apple introduces the MacBook Pro, its first Intel-
based, dual-core mobile computer, as well as an Intel-based
iMac. Nintendo's Wii game console hits the market.
• 2009: Microsoft launches Windows 7, which offers the ability
to pin applications to the taskbar and advances in touch and
handwriting recognition, among other features.
• 2010: Apple unveils the iPad, changing the way consumers
view media and jumpstarting the dormant tablet computer
segment.
• 2011: Google releases the Chromebook, a laptop that runs the
Google Chrome OS.
• 2015: Apple releases the Apple Watch. Microsoft releases
Windows 10.
• 2016: The first reprogrammable quantum computer was
created. "Until now, there hasn't been any quantum-
computing platform that had the capability to program new
algorithms into their system.
Generation of Computers
First Generation of Computer (1937 – 1946):
• In 1937 the first electronic digital computer was built by Dr. John V.
Atanasoff and Clifford Berry.
• It was called the Atanasoff-Berry Computer(ABC). In 1943 an electronic
computer name the Colossus was built for the military. Other
developments continued until in 1946 the first general– purpose digital
computer, the Electronic Numerical Integrator and Calculator (ENIAC) was
built.
• It is said that this computer weighed 30 tons, and had 18,000 vacuum
tubes which was used for processing. When this computer was turned on
for the first time lights dim in sections of Philadelphia.
• Computers of this generation could only perform single task, and they had
no operating system.
Characteristics:
• Sizes of these computers were as large as the size of a room.
• Possession of Vacuum Tubes to perform calculation.
• They used an internally stored instruction called program.
• Use capacitors to store binary data and information.
• They use punched card for communication of input and output data
and information
• They generated a lot of heat.
• They have about One Thousand 1000 circuits per cubic foot.
Examples:
• Mark I developed by Aiken in 1944.
• Electronic Numerical Integrator and Calculator (ENIAC) built at
the Moore School for Engineering of the University of
Pennsylvania in 1946 by J. Presper Eckert and William Mauchley.
• Electronic Discrete Variable Automatic Computer (EDVAC) also
developed in 1947 by Eckert and Mauchley.
Second Generation of Computer (1947 –
1962):
• Second generation of computers used transistors instead of vacuum
tubes which were more reliable.
• In 1951 the first computer for commercial use was introduced to the
public; the Universal Automatic Computer (UNIVAC 1).
• In 1953 the International Business Machine (IBM) 650 and 700 series
computers made their mark in the computer world.
• During this generation of computers over 100 computer programming
languages were developed, computers had memory and operating
systems. Storage media such as tape and disk were in use also were
printers for output.
Characteristics:
• The computers were still large, but smaller than the first generation of
computers.
• They use transistor in place of Vacuum Tubes to perform calculation.
• They were produced at a reduced cost compared to the first generation of
computers.
• Possession of magnetic tapes as for data storage.
• They were using punch cards as input and output of data and information.
• The use of keyboard as an input device was also introduced.
• These computers were still generating a lot of heat in which an air
conditioner is needed to maintain a cold temperature.
• They have about one thousand circuits per cubic foot.
Example:
• Leprechaun, IBM built by Bell Laboratories in 1947
• Transis produced by philco, GE and RCA.
• UNIVAC 1107, UNIVAC III.
• RCA 501v. IBM 7030 stretch.
Third Generation of Computer (1963 – 1975):
•The invention of integrated circuit brought us
the third generation of computers.
•With this invention computers became smaller,
more powerful more reliable and they are able
to run many different programs at the same
time.
Characteristics:
• They used large-scale integrated circuits, which were used for both
data processing and storage.
• Computers were miniaturized, that is, they were reduced in size
compared to previous generation.
• Keyboard and mouse were used for input while the monitor was used
as output device.
• Use of programming language like COBOL and FORTRAN were
developed.
• They have hundred thousand circuits per cubic foot.
Examples:
• Burroughs 6700, Mini computers
• Honeywell 200
• IBM system 360
• UNIVAC 9000 series.
Fourth Generation of Computer (PC 1975 –
Current)
• At this time of technological development, the size of computer was
redivided to what we called Personal Computers, PC.
• This was the time the first Microprocessor was created by Intel.
• The microprocessor was a very largescale, that is, VLS integrated circuit
which contained thousands of transistors.
• Transistors on one chip were capable performing all the functions of a
computer’s central processing unit.
Characteristics:
• Possession of microprocessor which performs all the task of a
computer system use today.
• The size of computers and cost was reduced.
• Increase in speed of computers.
• Very large scale (VLS) integrated circuits were used.
• They have millions of circuits per cubic foot.
Examples:
• IBM system 3090, IBM RISC6000, IBM RT.
• ILLIAC IV.
• Cray 2 XMP. iv. HP 9000.
• Apple Computers.
Fifth Generation of Computers (Present and
Beyond)
• Fifth generations computing devices, based on artificial
intelligence (AI) are still in development, although there are
some application such as voice recognition, facial face
detector and thumb print that are used today.
Characteristics:
• Consist of extremely large scale integration.
• Parallel processing
• Possession of high speed logic and memory chip.
• High performance, micro-miniaturization.
• Ability of computers to mimic human intelligence, e.g. voice
recognition, facial face detector, thumb print.
• Satellite links, virtual reality.
• They have billions of circuits per cubic.
Examples:
• Super computers
• Robots
• Facial face detector
• Thumb print.
CLASSIFICATION OF COMPUTERS
➢Computers can be broadly classified into four categories based
on their speed, amount of data that they can process, and price.
• Supercomputers
• Mainframe computers
• Minicomputers
• Microcomputers
CLASSIFICATION OF COMPUTERS
Supercomputers
• Among the four categories, the supercomputer is the fastest, most
powerful, and most expensive computer.
• Supercomputers were first developed in the 1980s to process large
amounts of data and to solve complex scientific problems.
• Supercomputers use parallel processing technology and can perform
more than one trillion calculations in a second.
SuperComputers
• A single supercomputer can support thousands of users at the same
time.
• Such computers are mainly used for weather forecasting, nuclear
energy research, aircraft design, automotive design, online banking,
controlling industrial units, etc.
• Some examples of supercomputers are CRAY-1, CRAY-2, Control Data
CYBER 205, and ETA A-10.
Mainframe Computers
• Mainframe computers are large-scale computers (but smaller than
supercomputers).
• These are very expensive and need a very large clean room with air
conditioning, thereby making them very costly to deploy.
• As with supercomputers, mainframes can also support multiple
processors.
Mainframe Computers
• For example, the IBM S/390 mainframe can support
50,000 users at the same time.
• Users can access mainframes by either using terminals
or via PCs.
The two types of terminals that can be used with
mainframe systems are as follows:
• Dumb Terminals
• Intelligent Terminals
Dumb Terminals and Intelligent Termianals
➢Dumb Terminals :
• Dumb terminals consist of only a monitor and a keyboard
(or mouse).
• They do not have their own CPU and memory and use the
mainframe system’s CPU and storage devices.
➢Intelligent Terminals:
• Intelligent terminals have their own processor and thus can
perform some processing operations.
• However, just like the dumb terminals, they do not have their
own storage space.
• Usually, PCs are used as intelligent terminals to facilitate data
access and other services from the mainframe system.
Minicomputers
• As the name suggests, minicomputers are smaller, cheaper, and
slower than mainframes.
• They are called minicomputers because they were the smallest
computer of their times.
• Also known as midrange computers , the capabilities of
minicomputers fall between mainframe and personal computers.
• Minicomputers are widely used in business, education, hospitals,
government organizations, etc.
• While some minicomputers can be used only by a single user,
others are specifically designed to handle multiple users
simultaneously.
• Usually, single-user minicomputers are used for performing
complex design tasks.
Microcomputers
• Microcomputers, commonly known as PCs, are very small
and cheap.
• The first microcomputer was designed by IBM in 1981 and
was named IBM-PC.
• Later on, many computer hardware companies copied this
design and termed their microcomputers as PC-compatible,
which refers to any PC that is based on the original IBM PC
design.
Types of Microcomputers
• Another type of popular PC is designed by Apple.
• PCs designed by IBM and other PC-compatible computers
have a different architecture from that of Apple computers.
• PCs and PC-compatible computers commonly use the
Windows operating system, while Apple computers use the
Macintosh operating system (MacOS).
PCs can be classified into the following categories:
• Desktop PCs
• Laptops
• Workstations
• Network Computers
• Handheld Computers
Desktop PCs
• A desktop PC is the most popular model of PCs.
• The system unit of the desktop PC can be placed flat on a desk or
table.
• It is widely used in homes and offices
Laptops
• Laptops are small microcomputers that can easily fit inside a
briefcase.
• They are very handy and can easily be carried from one place
to another.
• They may also be placed on the user’s lap (thus the name).
• Workstations are single-user computers that have the
same features as PCs, but their processing speed matches
that of a minicomputer or mainframe computer.
• Workstation computers have advanced processors, more
RAM and storage capacity than PCs.
• Therefore, they are more expensive and powerful than a normal
desktop computer.
• Workstation computers are widely used as powerful single-user
computers by scientists, engineers, architects, and graphic
designers, they can also be used as servers in a networked
environment.
Network Computers
• Network computers have less processing power, memory, and storage
than a desktop computer.
• These are specially designed to be used as terminals in a networked
environment.
• For example, some network computers are specifically designed to
access data stored on a network
Network Computers
Handheld Computers
• The mid-1990s witnessed a range of small personal computing
devices that are commonly known as handheld computers, or mobile
computers.
• These computers are called handheld computers because they can fit
in one hand, while users can use the other hand to operate them.
• Some examples of handheld computers are as follows:
• Smartphones
• Tablet PCs
APPLICATIONS OF COMPUTERS
• Word processing: Word processing software enables users to read and
write documents.
• Internet: The Internet is a network of networks that connects computers
all over the world.
• Digital video or audio composition: Computers make audio or video
composition and editing very simple
• Desktop publishing: Desktop publishing software enables us to create page
layouts for entire books
• Different areas where computers are being widely utilized:
• e-Business or electronic business is the process of conducting
business via the Internet.
• Business-to-consumer or B2C In this form of electronic commerce,
business companies deploy their websites on the Internet to sell their
products and services to the customers.
• Business-to-business or B2B This type of electronic commerce
involves business transactions performed between business partners.
• Consumer-to-consumer or C2C This type of electronic commerce
enables customers to carry business transactions among themselves.
• Electronic banking, also known as cyberbanking or online banking,
supports various banking activities conducted from home, a business,
or on the road instead of a physical bank location.
Bioinformatics
• Bioinformatics is the application of computer technology to manage
large amount of biological information.
• Computers are used to collect, store, analyze, and integrate biological
and genetic information to facilitate gene-based drug discovery and
development.
Health care
• Computers have also become a necessary device in the health care
industry.
• The following are areas in which computers are extensively used in
the health care industry.
Storing records
Surgical procedures
Better diagnosis and treatment
Geographic Information System
• A geographic information system (GIS) is a computer
based tool for mapping and analyzing earth’s features.
• GIS manages location based information and provides
tools for display and analysis of statistics such as
population count,types of vegetation,and economic
development oppurtunities
Meteorology
• Meteorology is the study of the atmosphere.
• This branch of science observes variables of Earth’s atmosphere such
as temperature, air pressure, water vapour, and the gradients and
interactions of each variable, and how they change over time.
• Weather forecasting
• Aviation meteorology
• Agricultural meteorology
• Nuclear meteorology
• Maritime meteorology
Other Areas
•Multimedia and Animation
•Retail Business.
•Sports
•Travel and Tourism.
•Astronomy
•Education
•Industry and Engineering
BASIC ORGANIZATION OF A COMPUTER
• A computer is an electronic device that performs five major
operations:
• Accepting data or instructions (input)
• Storing data
• Processing data
• Displaying results (output)
• Controlling and coordinating all operations inside a computer
Input :
• This is the process of entering data and instructions (also known
as programs ) into the computer system.
• The data and instructions can be entered by using different
input devices such as keyboard, mouse, scanner.
• Computers understand binary language, which consists of only
two symbols (0 and 1), so it is the responsibility of the input
devices to convert the input data into binary codes.
Storage:
• Storage is the process of saving data and instructions
permanently in the computer so that they can be used for
processing.
• The computer storage space not only stores the data and
programs that operate on that data but also stores the
intermediate results and the final results of processing.
• A computer has two types of storage areas:
• Primary storage
• Secondary storage
Output:
• Output is the process of giving the result of data
processing to the outside world (external to the
computer system).
• The results are given through output devices such as
monitor, and printer.
Control:
• The control unit (CU) is the central nervous system of the
entire computer system.
• It manages and controls all the components of the
computer system.
• It is the CU that decides the manner in which instructions
will be executed and operations performed.
• It takes care of the step-by-step processing of all
operations that are performed in the computer.
• CPU is a combination of the arithmetic logic unit (ALU)
and the CU.
Processing:
• The process of performing operations on the data as per the
instructions specified by the user (program) is called
processing
• Data and instructions are taken from the primary memory
and transferred to the ALU, which performs all sorts of
calculations.
• The intermediate results of processing may be stored in the
main memory, as they might be required again.
• When the processing completes, the final result is then
transferred to the main memory.
INPUT AND OUTPUT DEVICES
Input Devices
INPUT DEVICES
Keyboard: Every computer supports a keyboard – either a physical or
touchscreen. The keyboard has QWERTY layout and contains large number of
symbols. Each letter, numeral or symbol is known as a character, which
represents smallest piece of information. Each character has a unique values
called the ASCII (American Standard Code for Information Interchange) value.
Pointing Devices: GUI (Graphical User Interfaces) like windows need a pointing
device to control the movement of cursor on the screen. This is implemented as
mouse in desktop and touchpad in laptop. The earliest form has a rotating ball
and two buttons. The left button is used for selecting (by clicking once) and
execute (by clicking twice). The right button is used to check and change
attributes. The optical mouse uses infrared laser/LED, the wireless mouse uses
radio frequency technology.
Keyboard
Pointing Devices
Handheld Devices
Optical devices
Scanner: A scanner is a device that creates a digital image of a document by
optically scanning it. The flatbed scanner doesn’t exceed more than A4 size. It
is operated with by using special software. The document to be scanned is
placed on a glass plate covered by lid. Modern scanners have OCR (Optical
Character Recognition) facility which extracts text as a stream of characters
i.e. converting image file to text file and MICR (Magnetic Ink Character
Recognition) reads the codes using hand held barcode readers.
Barcode Readers: is a input device that is used to capture and read
information stored in a barcode.
OUTPUT DEVICES
Monitor: The monitor is an integral part of computer which displays both text
and graphics. The performance is measured in terms of image quality, resolution,
energy consumption.
CRT (Cathode Ray Tube) Monitors: The CRT monitors have a rarefied tube
containing three electron guns. The guns emit electrons create images. They
usually have resolution of 640*840 pixels. They are large, heavy, energy
efficient and produces lot of heat.
LCD (Liquid Crystal Display) Monitors: The image is formed by applying voltage
on crystals. The backlight is provided by fluorescent light. They consume less
power, generate less heat and have increased life span.
CRT AND LCD MONITORS
Impact Printers
It produces the hardcopy of output. The impact printers are old, noisy.
But, still dot-matrix printer is in usage
Dot-Matrix Printer: The print head of the dot-matrix printer
has either 9 or 24 pins. When the pins fire against the ribbon, an
impression is created on the paper. The speed is 300 cps and
doesn’t produce high quality output. It can produce multiple
copies.
Daisy-wheel Printer: It employs a wheel with separate
characters distributed along its outer edge. The wheels can be
changed to obtain different set of fonts.
Line Printer: For heavy printing, the line printer is used. It uses a
print chain containing the characters. Hammers strike the paper
to print and it rotates at the speed of 1200 lpm. It is also noisy
and is of low-quality.
Non-Impact Printers
They are fast, quiet and of high resolution. The most commonly used non-impact printers are laser and
ink-jet printers. The thermal printer is not discussed here because it uses heat to print on high-
sensitive paper.
Laser Printer: It works like a photocopier and uses toner i.e.
black magnetic powder. The image is created in the form of dots
and passed from drums on to the paper. It has built-in RAM
which acts as buffer and RAM to store fonts. The resolution
varies from 300 dpi to 1200 dpi(dots per inch) and the speed is
about 20 ppm(pages per minute).
Ink-jet Printer: These are affordable printers. It sprays tiny
drops of ink at high pressure as it moves along the paper. The
separate cartridges are available for different colors. The
resolution is about 300 dpi, can print 1 to 6 pages/min.
Plotters: The plotter can make drawings. It uses one or more
automated pens. The commands are taken from special file called
vector graphic files. Depending on type of plotter either paper
or pen moves. It can handle large paper sizes and it is used for
creative drawings like buildings and machines. They are slow and
expensive.
Designing Efficient Programs
Programming Paradigms
•A programming paradigms is a fundamental style
of programming that defines how the structure
and basic elements of computer program will be
built.
Classification of Programming Paradigms
• Monolithic Programming: Emphasis on finding a
solution.
• Procedural Programming: lays stress on algorithms.
• Structured Programming: focuses on modules.
• Object Oriented Programming: emphasis on class and
objects
• Rule Oriented Programming: makes use of ‘if-then-
else’ rules for computation
Monolithic Programming
• Programs written using monolithic programming languages such
as assembly language and BASIC(Beginner’s All purpose
symbolic instruction code) consist of global data and sequential
code.
• The global data can be accessed and modified from any part of
the program.
• In order to change the sequence of instructions, jump
statements or ‘goto’ statements are used.
Procedural Programming
• In procedural languages, a program is divided into
subroutines that can access global data.
• A subroutine that needs the service provided by another
subroutine can call that subroutine.
• Therefore, with ‘jump’, ‘goto’ and ‘call’ instructions, the
sequence of execution of instructions can be altered.
• FORTRAN and COBOL are two popular procedural
programming languages.
Advantages
•The only goal is to write correct programs.
•Programs are easier to write as compared to
monolithic programming.
Disadvantages
•No concept of reusability
•Requires more time and effort to write
programs.
•Programs are difficult to maintain.
•Global data is shared and therefore may get
altered.
Structured programming
• Structured programming, also referred to as modular
programming.
• It was specifically designed to enforce a logical
structure on the program to make it more efficient
and easier to understand.
• Structured programming was basically defined to be
used in large programs that require large
development team to develop different parts of the
same program.
• Structured programming employs a top-down approach
in which the overall programs structure is broken down
into separate modules.
• Modules are coded separately and once a module is
written and tested individually, it is then integrated with
other modules from the overall program structure.
• Modularization makes it easier to write, debug and
understand the program.
• For large and complex programs, the overall program
structure may further require the need to break the modules
into subsidiary pieces.
• This process continues until an individual piece of code can
be written easily.
• Almost every modern programming language similar to C,
pascal, etc., supports the concept of structured
programming.
Object- Oriented Programming(OOP)
• It treats the data as a critical element in the program
development and restricts its flow freely around the system.
• In this paradigm, all the relevant data and tasks are grouped
together in entities known as objects.
• In the object oriented paradigm, the list and the associated
operations are treated as one entity known as an object.
• The major difference between OOP and traditional approach
is that the program accessing this list need not contain for
performing tasks, rather, it uses the routines provided in the
object.
Features of OOP
• Programs are data centered.
• Programs are divided in terms of objects and not procedures.
• Functions that operate on data are tied together with the data.
• Data is hidden and not accessible by external functions.
• New data and functions can be easily added as and when
required.
• Follows a bottom-up approach for problem solving.
Example of a structured program
➢Imagine that your institute wants to create a program to
manage the names and addresses of a list of students.
• For this you need to break down the program into following
modules:
• Enter new names and addresses
• Modify existing entries.
• Sort entities.
• Print the list.
• Now each of these modules can be further broken down into
smaller modules.
• For example, the first module can be subdivided into modules
such as follows:
• Prompt the user to enter new data.
• Read the existing list from the disk.
• Add the name and address to the existing list.
• Save the updated list to the disk.
•Similarly, ‘modify existing entries’ can be further
divided into modules such as follows:
•Read the existing list from disk
•Modify one or more entries
•Save the updated list to disk
• The structured programming method results in a
hierarchical or layered program structure, which is
depicted in the figure below:
Design and implementation of efficient programs
➢The phases in the software development life cycle (SDLC)
process in the figure.
➢The phases in the SDLC process can be summarized as follows:
• Requirement analysis
• Design
• Implementation
• Testing
• Software deployment, training, and support
• Maintenance
Requirement Analysis
• In this phase, the user’s expectations are gathered to know why the
program or software has to be built.
• All the gathered requirements are analysed to arrive at the scope or
the objective of the overall software product.
• The last activity in this phase includes documenting every identified
requirement of the users in order to avoid any doubts or uncertainty
regarding the functionality of the programs.
Design
• In the design phase, the core structure the software/program is
broken down into modules.
• The solution of the program is then specified for each module in the
from of algorithms or flowcharts.
• The design phase, therefore , specifies how the program/software will
be built.
Implementation
• In this phase, the designed algorithms are converted into
programs code using any of the high-level languages.
• The particular choice of language will depend on the type of
program, such as whether it is a system or an application
program.
• This phase is also called construction or code generation
phase.
Testing
• In this phase, all the modules are tested together to ensure that
overall system works well as a whole product.
• Although individual pieces of codes are already tested by the
programmers in the implementation phase.
Software deployment,training, and support
• After the code is tested and the software or the program
has been approved by the users, it is installed or
deployed in the production environment.
Maintenance
• Maintenance and enhancements are ongoing activities that are done
to cope with newly discovered problems or new requirements.
• Such activities may take a long time to complete as the requirement
may call for the addition of new code that does not fit the original
design or an extra piece of code, required to fix an unforeseen
problem.
Programs Design Tools: Algorithms,
Flowcharts, Pseudocodes
Algorithms
• The typical meaning of an algorithm is a formally defined
procedure for performing some calculation.
• If a procedure is formally defined, then it must be implemented
using some formal language, and such languages are known as
Programming Languages.
• An algorithm provides a blueprint to writing a
program to solve a particular problem.
• It is considered to be an effective procedure for
solving a problem in a finite number of steps.
Control structures used in Algorithms
➢An algorithm may employ three control
structures namely,
•Sequence
•Decision
•Repetition
Sequence
• Sequence means that each step of the algorithm is executed in the specified
order.
• An algorithm to add two number is given below:
• Step 1: Input first number as A
• Step 2: Input second number as B
• Step 3: Set Sum = A + B
• Step 4: Print Sum
• Step 5: End
• This algorithm performs the steps in a purely sequential order.
Decision
• Decision statements are used when the outcome of the
process depends on some condition.
• If x = y, then print “EQUAL”.
• Hence the general form of the if construct can be given as
follows:
• IF condition then process
•A condition in this context is any statement that
may evaluate either to a true value or a false value.
•Variable x can either be equal or not equal to y.
•It cannot be both true and false.
•If the condition is true then the process is
executed.
• The decision statement can also be stated in the following
manner:
IF condition
then process1
ELSE process2
This form is commonly known as the if-else construct.
Here, if the condition is true then process1 is executed, else
process2 is executed.
➢An algorithm to check the equality of two numbers is shown
below.
• Step 1: Input first number as A
• Step 2: Input second number as B
• Step 3: IF A = B
Print “Equal”
ELSE
Print “Not equal”
[END of IF]
• Step 4: End
Repetition
• Repetition, which involves executing one or more steps for a
number of times, can be implemented using constructs such as the
while, do-while, and for loops.
• This loops execute one or more steps until some condition is true.
• Below is an algorithm that prints the first 10 natural numbers.
Step 1: [initialize] Set i = 1, N = 10
Step 2: Repeat steps 3 and 4 while i<= N
Step 3: Print i
Step 4: SET i = i+ 1
[END OF LOOP]
Step 5 : END
Algorithm Examples
• Write an algorithm for interchanging/swapping two values:
Write an algorithm to find larger of two numbers:
Write an algorithm to find whether a number is even or odd:
Write an algorithm to print the grade obtained by a
student using following rules:
Write an algorithm to find the sum of first N natural
numbers:
Flowcharts
• A flowchart is a graphical or symbolic representation of a
process.
• It is basically used to design and document virtually complex
processes, so that they can gain a better understanding of the
process.
• When designing a flowchart, each step in the process is
depicted by a different symbol and is associated with a short
description.
• The symbols in the flowchart are linked together with arrows to
show the flow of logic in the process.
Symbols of flowchart
➢The symbols used in a flowchart include the following:
• Start and end symbols are also known as the terminal symbols
and are represented as circles, ovals, or rounded rectangles.
• Arrows depict the flow of control of the program.
• Generic processing step, also called as an activity, is represented
using a rectangle.
• Input/output symbols are represented using a parallelogram
and are used to get inputs from the users or display a results to
them.
• A conditional or decision symbol is represented using a
diamond.
• Labelled connectors are represented by an identifying
label inside a circle and are used in complex programs.
Examples
• Draw a flowchart to calculate the sum of the first 10 natural numbers.
• Draw a flowchart to add two numbers.
• Draw a flowchart to calculate the salary of a daily wager.
• Draw a flowchart to determine the largest of three numbers.
PSEUDOCODE
➢ Pseudocode is an informal list of steps in English like statements which is intended for
human reading.
➢It is used in planning of computer program development, for sketching out the structure of
the program before the actual coding takes place.
Advantages:
Disadvantages:
1. It can be written easily
1. There is no standard form.
2. It can be read and understood easily
3. Modification is easy [Link] Pseudocode may vary from other for same
problem statement.
Pseudocode:
Addition of two numbers Area of Rectangle
1. Begin 1. Begin
2. Read two numbers a, b 2. Read the values of length, breadth
3. Calculate sum = a+b 3. Calculate area = l x b
4. Display area
4. Display sum
5. End
5. End
Types of errors
•While writing programs, very often we get errors
in our programs.
•These errors if not removed will either give
erroneous output or will not let the compiler to
compile the program.
Run - time errors
• As the name suggests, run-time errors occur when the program is run
executed.
• Such errors occur when the program perform some illegal operations like
• Dividing a number by zero
• Opening a file that already exists
• Lack of free memory space
• Finding square of logarithm of negative numbers
Compile-time errors
• Compile time errors occur at the time of compilation of the
program.
• Such errors can be further classified as follows:
Compile-time errors occur at the time of compilation of the
program.
Syntax errors are generated when rules of a programming
language are violated.
Semantic errors is erroneous logic that produces the wrong result
when executed.
Logical errors
• Logical errors are errors in the program code that result
in unexpected and undesirable output which is obviously
not correct.
• Such errors are not detected by the compiler, and
programmers must check their code line by line or use a
debugger to locate the errors.
• Logical errors occur due to incorrect statements
Linker error
•These errors occur when the linker is not able to find
the function definition for a given prototype.
INTRODUCTION TO C
Structure of a C Program
• The pre-processor directives contain special instructions that
indicate how to prepare the program for compilation.
• One of the most important and commonly used pre-processor
command is include which tells the compiler that to execute the
program, some information is needed from the specified header
file.
• A C program contains one or more functions, where a function is
defined as a group of C statements that are executed together.
• The main() function is the most important function and is a part
of every C program.
• The execution of a C program begins at this function.
Main() function
• All functions (including main()) are divided into two parts- the declaration
section and the statement section.
• The declaration section precedes the statement section and is used to
describe the data that will be used in the function.
• The data declared within a function are known as local declarations as
that data will be visible only within that function.
• The statement section in a function contains the code that manipulates
the data to perform a specified task.
• From the structure given above we can conclude that a C program can
have any number of functions depending on the tasks that have to be
performed, and each function can have any number of statements
arranged according to the specific meaningful sequence.
Writing the first C Program
#include<stdio.h>
int main()
{
printf(“\n welcome to the world of C”);
return 0;
}
Output:
welcome to the world of C
Files used in the Program
Source Code Files
• The source code file contains the source code of the
program.
• The file extension of any C source code file is ‘.c’.
• This file contains C source code that defines the main
function and may be other functions.
• The main() function is the starting point of execution when
you successfully compile and run the program.
Header files
• When working with large projects, it is desirable to separate out
certain subroutines from the main() function.
• The advantages of header files can be realized in the following
cases:
• The programmer wants to use the same subroutines in different
programs.
• The programmer wants to change or add subroutines, and have
those changes reflected in all other programs.
Standard Header Files
➢Examples of these standard files include:
• string.h : for string handling functions
• stdlib.h : for some miscellaneous functions
• stdio.h : for standardized input and output functions
• math.h : for mathematical functions
• alloc.h : for dynamic memory allocation
• conio.h : for clearing the screen,console i/p and o/p.
Object Files
• Object files generated by the compiler as a result of processing
the source code file.
• Object files contain compact binary code of the function
definition.
• Linker uses these object files to produce an executable file (.exe
file) by combining the object files together.
• Object files have a ‘.o’ extension.
• Although some operating systems including windows and MS-
DOS have a ‘.obj’ extension for the object file.
Binary Executable Files
• The binary executable file is generated by the linker.
• The linker links the various object files to produce a
binary file that can be directly executed.
• On windows operating system, the executable files
have a ‘.exe’ extension.
Compiling and Executing C programs
Compiling and Executing C programs
• The programming process starts with creating a source file that
consists of the statements of the program written in C language.
• The source code is then processed by a special program called a
compiler.
• The compiler translates the source code into an object code.
• However, even the object file is not an executable file.
• Therefore, in the next step, the object file is processed with another
special program called a linker.
• The output of the linker is an executable or runnable file.
Using Comments in C
• To understand the purpose of the program ,use comments.
➢C supports 2 types of comments:
• // is used to comment single [Link] is known as line
comment.
• Line comment can be placed anywhere on the line.
• /* is used to comment multiple lines of statements.
• This type of comment is called as block comment
/*……………………………………………………………
………………………………………………………….
*/
CHARACTER SET IN C
A C character set defines the valid characters that can be used in a source
program.
The basic C character set are:
1. Letters: Uppercase: A,B,C,….,Z
Lowercase: a,b,c,…..,z
2. Digits: 0,1,2,…..,9
3. Special characters: ! , . # $ ( ) } { =,@,$,%,&.. etc
[Link] spaces: Blank space, Horizontal tab space (\t), carriage return,
new line character (\n), form feed character.
C – TOKENS
It is also called as lexical unit. There are 6 types
The smallest individual unit in ‘C’ of ‘C’ tokens:
i. Keywords
program is called as C-Token. ii. Identifiers
These are the building blocks of ‘C’ iii. Constants
iv. Strings
program.
v. Operators
vi. Special symbols
Keywords
Keywords are also called as reserved words.
They already have pre-defined meaning.
Keywords should always be written in lowercase.
The keywords meaning can’t be changed.
Keywords cannot be used as identifiers.
There are 32 keywords in ‘C’ program.
Identifiers
It refers to the name of the objects.
These are the names given to variables, functions, macros etc.
The rules to write an identifier are as follows:
❖ It must contain only alphabets (A to Z, a to z), numbers (0 to 9) and
underscore ( _ ).
❖ It must start with alphabet or underscore but not numeric character.
❖ It should not contain any special symbols apart from underscore.
❖ It should not have any space.
❖ Keywords cannot be used as identifiers.
❖ Identifiers are case sensitive.
❖ Maximum length of an identifier is 31 characters.
Examples:
Valid Identifiers: integer, minimum,
sum_total, row1, _cpps
Invalid Identifiers:
float //It is a keyword.
I am //It has space
123_Abc //It is starting with number
N1 + n2 //It contains special symbol (+)
Constants
Constants
•Constants are identifiers whose values do not
change.
•Values of constants can never be changed.
•Constants are used to define fixed values like
constant pi .
Integer Constants
Examples
• For eg:1,34,567,8907 are valid integer constants.
• Decimal integer constants include 123,+123,-123..
• While writing integer constants, embedded
spaces,commas, and non-digit characters are not allowed.
• a)123 456, b)12,34,567 c)$123:invalid
• Egs: for octal integers include 012,01234..
• Hexadecimal numbers include 0x12 ,0x7F,0xABCD
Floating point Constant
• These are the numbers with decimal part and exponent part.
• These are also called as floating point constant.
• The floating values can be identified by the suffix ‘F’ or ‘f’
• It can be expressed in exponential form.
Character Constants
•These are the values enclosed within single
quotes.
•For example ‘a’ and ‘@’ are character
constants.
•Each character have an integer value called as
ASCII (American Standard Code for
Information Interchange) A: 65, a: 97
String Constants
• A group of characters together form a string.
• Strings are enclosed within double quotes.
• They end with NULL character (\0).
• Ex: “CBIT”
Declaring Constants
Qualified Constant/ Memory Constant: These are created by using “const” qualifier. Const means
that something can only be read but not modified.
Syntax: const datatype variable_name = value;
Ex:
const int a = 10;
const float pi = 3.14
Symbolic Constants/ Defined Constant: These are created with the help of define
preprocessor directive.
Ex: #define PI 3.142
#define SERVICE_TAX 0.12
➢ During processing the PI in the program will be replaced with 3.142.
➢ The name of constant is written in uppercase just to differentiate from the variables.
Basic Data Types
Data types
What is a Byte?
• In most computer systems, a byte is a unit of data that is
eight binary digits long.
• A byte is the unit most computers use to represent a
character such as a letter, number or typographic symbol.
• Each byte can hold a string of bits that need to be used in
a larger unit for application purposes.
2. Floating point data type:
➢ It is used to store decimal numbers.
➢ The keyword float is used to declare variable of floating point data type.
➢ Float type takes 4B or 8B of storage depending on machine size.
➢ It can be expressed in fractional or exponential form.
VARIABLES
A variable is a name given to memory
location whose value changes during Initialization:
execution. Syntax: datatype variable_name = value;
Where,
✓ Declaration:
datatype → Any built in data type
Syntax: datatype variable_list;
Where,datatype Any built in data type variable_name → Identifier that specifies variable
→ Identifiers that specifies name. value → The data which will be stored in
variable_list variable name.
→variableExample: int a; Example: int a = 10;
Where, Where,
name.
int is the built in data type int → data type
a is variable of type int. a → variable name
10 → value
Initializing variables
• Int emp_num=7;
• Float salary=2156.35;
• Char grade=‘A’;
• double balance_Amount=100000000;
• Int count,flag=1;
Input output statements in C
• Printf() function (stands for print formatting)is used to display
information required by the user and also prints the values of
variables.
• The function accept two parameters-control string and variable
list.
➢Printf(“control string”,variable list);
Type specifiers for printf()
Type Qualifying input
c for single characters
d for integer values
f for floating pt numbers
E,e for point numbers in exponential format
s for sequence of characters.
Scanf()
•Scanf() function stands for scan formatting and is
used to read formatted data from the keyboard.
➢scanf(“%d %c”, &i, &ch);
Valid and invalid statements
scanf(“%d %d”,&num1,&num2,&num3);
scanf(“%d %d”,&num1,&num2,num3);
scanf(“%d / %d”,&num1,&num2);