0% found this document useful (0 votes)
29 views131 pages

Intro To C-Module-1

This document outlines topics covered in an Introduction to C Programming course. The topics are organized into modules. Module 1 covers basics of computers like characteristics, stored program concept, computer generations and history. It also discusses computer components like CPU, memory, input/output devices. Programming concepts like paradigms, algorithms, errors and debugging are introduced. Finally, it covers basics of C programming like structure of a C program, data types, variables, constants and input/output statements.

Uploaded by

neelagund
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views131 pages

Intro To C-Module-1

This document outlines topics covered in an Introduction to C Programming course. The topics are organized into modules. Module 1 covers basics of computers like characteristics, stored program concept, computer generations and history. It also discusses computer components like CPU, memory, input/output devices. Programming concepts like paradigms, algorithms, errors and debugging are introduced. Finally, it covers basics of C programming like structure of a C program, data types, variables, constants and input/output statements.

Uploaded by

neelagund
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 131

22BESCK104E/204E- Introduction to C

Introduction to C
Programming
Subject Code :22BESCK104E/204E
Module-1 Topics
1.1 Computer
1.2 Characteristics of Computers
1.3 Stored Program Concept
1.3.1 Types of Stored Program Computers
1.4 History of Computers
1.5 Classification of Computers
1.5.1 Supercomputers
1.5.2 Mainframe Computers
1.5.3 Minicomputers
1.5.4 Microcomputers
1.6 Applications of Computers
1.7 Basic Organization of a Computer
1.8 Lab Session—Inside the Computer
1.9 Motherboard
1.9.1 Characteristics of a Motherboard
Module-1 Topics

1.10 Input Devices


1.10.1 Keyboard
1.10.2 Pointing Devices
1.10.3 Handheld Devices
1.10.4 Optical Devices
1.10.5 Audiovisual Input Devices
1.11 Output Devices
1.11.1 Soft Copy Devices
1.11.2 Hard Copy Devices
1.12 Programming Paradigms
1.12.1 Monolithic Programming
1.12.2 Procedural Programming
1.12.3 Structured Programming
1.12.4 Object-oriented Programming (OOP)
1.13 Example of a Structured Program
Module-1 Topics

1.14 Design and Implementation of Efficient Programs


1.15 Program Design Tools: Algorithms, Flowcharts, Pseudocodes
1.15.1 Algorithms
1.15.2 Control Structures Used in Algorithms
1.15.2 FLOWCHARTS
1.15.3 Pseudocodes
1.16 Types of Errors
1.17 Testing and Debugging Approaches
1.18 Introduction to C
1.18.1 Characteristics of C
1.18.2Uses of C
1.19 Structure of a C Program
1.20 Writing the first C Program
Module-1 Topics

1.21 Files Used in a C Program


1.21.1 Source Code Files
1.21.2 Header Files
1.21.3 Object Files
1.21.4 Binary Executable Files
1.22 Compiling and Executing C Programs
1.23 Using Comments
1.24 C Tokens
1.25 Character Set in C
1.26 Keywords
1.27Identifiers
1.27.1 Rules for Forming Identifier Names
1.28 Basic Data Types in C
1.28.1 How are float and double stored
Module-1 Topics
1.29 Variables
1.29.1 Numeric Variables
1.29.2 Character Variables
1.29.3 Declaring Variables
1.29.4 Initializing Variables
1.30 Constants
1.30.1 Integer Constants
1.30.2 Floating Point Constants
1.30.3 Character Constants
1.30.4 String Constants
1.30.5 Declaring Constants
1.31 Input/output Statements in C
1.31.1 Streams
1.31.2 Formatting Input/output
1.31.3 printf()
1.31.4 scanf()
Day-1

1.1 Computer
1.2 Characteristics of Computers
1.3 Stored Program Concept
1.3.1 Types of Stored Program Computers
1.4 History of Computers
1.1 Computer

Definition of Computer : Computer is an electronic device that is


designed to accept data, perform the required mathematical and
logical operations at high speed, and output the result.
or
Computer is an electronic device that accept data from the user ,
perform the required operations , and output the result to the user.
1.2 Characteristics of Computer

Characteristics of Computer : Following are the characteristics of


computer.
1. Speed
2. Accuracy
3. Memory
4. No IQ
5. Economical
6. Automation
7. Diligence
8. Versatility
Characteristics of Computer

Speed : Computers can perform millions of operations per


second .The speed of
computers is usually given in nanoseconds and picoseconds, where 1
nanosecond = 1 × 10−9 seconds and 1 picosecond = 1 × 10−12
seconds.
Accuracy :Computer always gives accurate results, provided the
correct data and set of instructions are input to it.
Memory : Computer can stored large amount of data and programs
in the secondary storage space like ( CD, Floppy, DVD , Hard Disk
and pen drives). When data and programs have to be used, they are
copied from the secondary memory into the internal memory, often
Characteristics of Computer

No IQ : Computers do not have any decision-making abilities of


their own. They need guidance to perform various tasks.
Economical : Computer reduces manpower requirements and leads
to an elegant and efficient way of performing various tasks and
computers save time, energy, and money. When compared to other
systems, computers can do more work in lesser time.
Automation : Computer apart from being very fast and accurate,
computers are automatable devices that can perform a task without
any user intervention. The user just needs to assign the task to the
computer, after which it automatically controls different devices
attached to it and executes the program instructions.
Characteristics of Computer

Diligence : Unlike humans, computers never get tired of a repetitive


task. It can continually work for hours without creating errors. Even
if a large number of executions need to be executed, each and every
execution requires the same
duration, and is executed with the same accuracy.
Versatility : Computers are versatile devices as they can perform
multiple tasks of different nature at the same time. Example the PC
that we use at home can be used to play a game, compose and send
e-mail and listen to the music.
1.3 Stored Program Concept

Stored Program Concept: Sir John von Neumann in late 1940s


introduced the stored program concept.

The following are the key characteristic features of this concept:


• Before any data is processed, instructions are read into memory.
• Instructions are stored in the computer’s memory for execution.
• Instructions are stored in binary form (using binary numbers - 0s
and 1s).
• Processing starts with the first instruction in the program, which is
copied into a control unit circuit. The control unit executes the
instructions.
Stored Program Concept

• Instructions written by the users are performed sequentially until


there is a break in the current flow.
• Input/Output and processing operations are performed
simultaneously. While data is being read/written, the central
processing unit (CPU) executes another program in the memory that
is ready for execution.
1.3.1 Types Stored Program Computers

Following are the types of Stored Program Computers based on Von


Neumann architecture
1. Shared memory for instructions and data

• Shared Memory for instructions and data : In this type of machine


instructions and data are selected one at a time. Data and
instructions are transferred to and from memory through a shared
data bus. Since there is a
single bus to carry data and instructions, process execution becomes
1.3.1 Types Stored Program Computers

2. Separate memory for instructions and data

• Separate Memory for instructions and data : In this type of


machine Instructions are selected serially from the instruction
memory and executed in the processor. When an instruction needs
data, it is selected from the data
memory. Since there are separate memories, execution becomes
faster.
1.4 History of Computers

Generations of Computers :

Following are the different generation of computers

 First Generation (1942 – 1955)


 Second Generation (1955 – 1964 )
 Third Generation ( 1964 – 1975)
 Fourth Generation (1975 – 1989)
 Fifth Generation ( 1989- present)
First Generation of Computers (1942-1955)

Hardware Technology : First generation computers were


manufactured using thousands of vacuum tubes.
Memory : Electromagnetic relay was used as primary memory and
punched cards were used to store data and
instructions.
Software Technology : Programming was done in machine or
assembly language.
Uses : Used for Scientific applications
Examples: ENIAC, EDVAC, EDSAC, UNIVAC I, IBM 701
First Generation of Computers (1942-1955)

Highlights First Generation of computers :


 They were the fastest calculating device of those times.
 Computers were too bulky and required a complete room for
storage.
 Highly unreliable as vacuum tubes emitted a large amount of heat
and burnt frequently.
 Required air-conditioned rooms for installation.
 Costly.
 Difficult to use.
 Required constant maintenance because vacuum tubes used
filaments that had limited life time.
Second Generation of Computers (1955-1964)

Hardware Technology : Second generation computers were


manufactured using transistors . Transistors were reliable, powerful,
cheaper, smaller, and cooler than vacuum tubes.
Memory : Magnetic core memory was used as primary memory;
magnetic tapes and magnetic disks were used to store data and
instructions. These computers had faster and larger memory than the
first generation computers.
Software Technology : Programming was done in high level
programming languages. Batch operating system was used.
Uses : Used for Scientific and commercial applications.
Examples : Honeywell 400, IBM 7030, CDC 1604, UNIVAC
Second Generation of Computers (1955-1964)

Highlights Second Generation of computers :


 Faster, smaller, cheaper, reliable, and easier to use than the first
generation computers.
 They consumed 1/10th the power consumed by first generation
computers.
 Bulky in size and required a complete room for its installation.
 Dissipated less heat than first generation computers but still
required air-conditioned rooms.
 Costly.
 Difficult to use.
Third Generation of Computers (1964-1975)
Hardware Technology : Third generation computers were
manufactured using integrated chips (ICs) . ICs consist of several
components such as transistors, capacitors, and resistors on a single
chip to avoid wired interconnections between components.
Memory : Larger magnetic core memory was used as primary
memory; larger capacity magnetic tapes and magnetic disks were
used to store data and instructions.
Software Technology : Programming was done in high level
programming languages such as FORTRAN, COBOL, Pascal, and
BASIC. Time sharing operating system was used. Software was
separated from the hardware.
Third Generation of Computers (1964-1975)

Highlights Third Generation of computers :


 Faster, smaller, cheaper, reliable, and easier to use than the second
generation computers.
 They consumed less power than second generation computers.
 Bulky in size and required a complete room for installation.
 Dissipated less heat than second generation computers but still
required air-conditioned rooms.
 Costly
 Easier to use and upgrade.
Fourth Generation of Computers (1975-1989)

Hardware Technology : Fourth generation computers were


manufactured using ICs with LSI (Large Scale Integrated) and later
with VLSI technology (Very Large Scale Integration). Use of personal
computers became widespread. High
speed computer networks in the form of LANs, WANs, and MANs
started growing. Besides mainframes, supercomputers were also used.
Memory : Semiconductor memory was used as primary memory,
large capacity magnetic disks were used as built-in secondary
memory. Magnetic tapes and floppy disks were used as portable
storage devices.
Software Technology : Programming was done in C and C++.
Fourth Generation of Computers (1975-1989)

Apple Mac OS and MS DOS were also released during this period.
Uses : Used for Scientific, commercial, interactive online, and
network applications
Examples : IBM PC, Apple II, TRS-80, VAX 9000, CRAY- 1, CRAY-
2, CRAY-X/M
Fifth Generation of Computers (1989-Present)

Hardware Technology : Fifth generation computers are


manufactured using ICs with ULSI (Ultra Large Scale Integrated)
technology.
Memory :Semiconductor memory is used as primary memory; large
capacity magnetic disks are used as built-in secondary memory.
Magnetic tapes and optical disks and USB flash drives were used as
portable storage devices.
Software Technology : Programming is done in high-level
programming languages such as Java, Python, and C#.
Uses : Used for Scientific, commercial, interactive online,
multimedia (graphics, audio, video), and network applications.
Day-2

1.5 Classification of Computers


1.5.1 Supercomputers
1.5.2 Mainframe Computers
1.5.3 Minicomputers
1.5.4 Microcomputers
1.6 Applications of Computers
1.7 Basic Organization of a Computer
1.8 Lab Session—Inside the Computer
1.5 Classification of Computers

The below diagram shows the classification of computers based on


their speed ,amount of data that they can process and their prices:
1.5.1 Super Computers
Super Computers :
 Super computers were developed in 1980 to process large amount
of data and complex scientific problems.
 Supercomputers use parallel processing technology and can
perform more than one trillion calculations in a second.
 Supercomputer is the fastest, most powerful, and most expensive
computer.
 A single Supercomputer can support thousands of users at the
same time.
 Super computers are mainly used for weather forecasting, nuclear
energy research, aircraft design, automotive design, online
1.5.2 Mainframe Computers
Main frame 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.
 mainframes can also support multiple processors. 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
Mainframe Computers

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.
 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.
1.5.3 Mini Computers

Mini Computers :
 Minicomputers are smaller, cheaper, and slower than mainframes.
They are 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.
 Some minicomputers can be used only by a single user, others are
specifically designed to handle multiple users simultaneously.
 Minicomputers can also be used as servers in a networked
environment, and hundreds of PCs can be connected to it.
1.5.4 Micro Computers

Micro Computers :
 Microcomputers, commonly known as PCs, are very small and
cheap. The first microcomputer was designed by IBM in 1981 and
was named IBM-PC.
 PCs can be classified into the following categories:
 Desktop PCs
 Laptops
 Workstations
 Networked Computers
 Handheld Computers
1.5.4 Micro Computers

Desktop PC :
 Desktop PC is the most popular model of PCs.
 It can be placed on the flat desk or a table
 It is used mainly in homes and offices.
Laptops :
 Laptops are small microcomputers that can easily fi t inside a
briefcase.
 They are very handy and can easily be carried from one place to
another.
 The memory and storage capacity of a laptop is almost equivalent
to that of a desktop computer.
1.5.4 Micro Computers

Workstations :
 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.
 They are more expensive and powerful than a normal desktop
computer.
 They are widely used as powerful single-user computers by
scientists, engineers, architects, and graphic designers, they can
also be used as
1.5.4 Micro Computers

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 servers in a networked
environment.
 Network computers that are specifically designed to access only
the Internet or intranet are often known as Internet PCs or Internet
boxes.
1.5.4 Micro Computers

Handheld :
 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 .
 They are called Handheld computers because they can fit in one
hand, while users can use the other hand to operate them.
 Handheld computers are very small in size, and hence they have
small-sized screens and keyboards.
 These computers are preferred by business travellers and mobile
employees
1.6 Applications of Computers

Computers are used in various fields :

Word processing : This software enables users to read and write the
documents and insert the images ,tables and graphs for illustrating
the concepts.
Internet :The Internet is a network of networks that connects
computers all over the world. It gives the user access to an enormous
amount of information, much more than available in any library.
Digital video or audio composition: Computers make audio or
video composition and editing very simple. This has drastically
reduced the cost of equipment to compose music or make a film.
1.6 Applications of Computers

Desktop Publishing : Desktop publishing software enables us to


create page layouts for entire books.
E-Business : e-Business or electronic business is the process of
conducting business via the Internet. This may include buying and
selling of goods and services using computers and the Internet.
Health Care : In Health care system computers are used to store the
records, surgical procedures and for Better diagnosis and treatment .
Geographic's and Information System and Remote Sensing : A
geographic information system (GIS) is a computer- based tool for
mapping and analysing earth’s features. It integrates database
operations and statistical analysis to be used with maps. GIS
1.6 Applications of Computers

for display and analysis of statistics such as population count, types


of vegetation, and economic development opportunities.
Remote sensing is the science of taking measurements of the
earth using sensors on airplanes or satellites. These sensors collect
data in the form of images, which are then analysed to derive useful
information.
Multimedia and Animation : Using animation software, we can
reproduce real- world phenomena such as fire, smoke, fluids,
movement of chemicals through the air and ground, and the
respiratory system to name a few.
Education System : A computer is a powerful teaching aid and can
1.6 Applications of Computers

presentations to easily illustrate an otherwise difficult concept.


Retail System : Computers are used in retail shops to enter orders,
calculate
costs, and print receipts. They are also used to keep an inventory of
the products available and their complete descriptions.
Travel and Tourism : Computers are used to prepare tickets,
monitor the train’s
or airplane’s route, and guide the plane to a safe landing. They are
also used to research about hotels in an area, reserve rooms, or to rent
a car.
Decision Support System :Computers help managers to analyse
1.7 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

The below diagram shows the block diagram of the computer


Basic Organization of 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, and trackball.
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
Basic Organization of a Computer

Primary Storage :
 Primary Storage is also known as main memory
 Primary storage is directly accessible by the CPU at very high
speeds.
 It is used to store the data and parts of programs, the
intermediate results of processing, and the recently generated
results of jobs that are currently
being worked on by the computer.
 Primary storage space is very expensive and therefore limited in
capacity.
 Primary storage is volatile memory.
Basic Organization of a Computer

Secondary Storage :
 Primary Storage is also known as aauxiliary memory.
 It is used to store the permanently data and parts of programs,
of jobs that are currently being executed on by the cpu.
 Secondary storage space is cheap.
 Secondary storage is non-volatile memory.
 Example of secondary memory is Hard disk.
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.
Basic Organization of a Computer

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.
 The CPU is known as the brain of the computer system because
the entire processing of data is done in the ALU, and the CU
Basic Organization of a Computer

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.
1.8 Lab Session : Inside the Computer

The following are some of the major parts of the computer :


 CPU
 RAM
 HDD
 Video Card
 Sound Card
 Modem
 Network Card
 Fans
 Cables
Lab Session : Inside the Computer

CPU : The CPU- Central processing unit is the brain of the


computer. It performs all calculations and controls the devices
connected to the computer system.
RAM : Random Access Memory is also called as main memory. It
stores the information about the applications that are currently
being executed by the cpu.
HDD : Hard disk drive is of the computer is the secondary memory
of the computer system where information is stored permanently.
All types of data,
documents, and programs are stored on the hard disk. The larger the
hard disk, the more the amount of data that can be stored on the
Lab Session : Inside the Computer

Video Card : The video card is a board that plugs into the
motherboard of the computer and generates images for display.
Many video cards these days have their own RAM and processor to
enhance the speed of the graphics display. Many computers come
with an in-built video chip.
Modem : A modem (modulator–demodulator) is a device that
enables the computer to use a telephone line to communicate and
connect to the Internet.
Network Card : A network card is used to connect the computer
either to other computers or to the Internet.
Lab Session : Inside the Computer

 Fans : Fans are used to allow air inside and cool the computer.
Cables : There are multiple wires inside the computer that are fl
at, ribbon-like cables. They are used to provide power and
communication to the various parts inside the computer.
Sound Card : sound cards are expansion boards that are used to
enable a computer to manipulate sound. For example, sound cards
allow the users to plug in speakers and a microphone. Some sound
cards also provide the jacks for hooking your computer up to a
common stereo.
Day-3
1.9 Mother Board
1.9.1 Characteristics of Motherboard
1.10 Input Devices
1.10.1 Keyboard
1.10.2 Pointing Devices
1.10.3 Handheld Devices
1.10.4 Optical Devices
1.10.5 Audiovisual Input Devices
1.11 Output Devices
1.11.1 Soft Copy Devices
1.11.2 Hard Copy Devices
1.12 Programming Paradigms
1.12.1 Monolithic Programming
1.12.2 Procedural Programming
1.12.3 Structured Programming
1.12.4 Object-oriented Programming (OOP)
1.9 Mother Board

 Motherboard:
The motherboard, also known as the mainboard or the parent
board.
Motherboard is the primary component of a computer.
It is used to connect all the components of the computer.
 The motherboard is a printed circuit that has connectors for
expansion cards, memory modules, the processor, etc.
1.9.1 Characteristics Mother Board

 Following are the characteristics of Motherboard:


Form Factor
Chipset
Types of Processor Sockets used
Input output Connectors

Form Factor : Form factor refers to the motherboard’s geometry,


dimensions, arrangement, and electrical requirements.
The mother board form factor describes its general shape, the type
of case and power supply it can use and its physical organization.
Characteristics Mother Board

Chipset : The chipset is an electronic circuit that basically


coordinates data transfers between the different components of the
computer (such as the processor and memory). Some chipsets may
include a graphics or audio chip, which makes it unnecessary to
install a separate graphics card or sound card.
Processor Sockets : is also known as CPU slot, the CPU socket is
used to connect a microprocessor with a printed circuit board (PCB)
without soldering, allowing the CPU to be installed or replaced
more easily on the motherboard
Common types of sockets are : PGA- Pin Grid Array and LGA
–Land grid Array
Characteristics Mother Board

Input Output Connectors : The motherboard has a number of


input–
output sockets on its rear panel, some of which include:
• A serial port to connect some old peripherals
• A parallel port to connect old printers
• USB ports to connect more recent peripherals such as mouse and
pen drive.
• RJ45 connector (also known as LAN or Ethernet port) to connect
the
computer to a network.
• Video graphics array (VGA) connector to connect a monitor.
1.10 Input Devices

Input Devices : Input devices is a device that is used to feed the


data and the instructions to the computer. Below diagram show
different input devices
1.10.1 Keyboard

Keyboard : Keyboard is the standard Input devices . It is used to


input data and instructions to the computer. It has alphabets,
numeric and symbol keys. It also contains special key including
function keys,control keys and arrow keys
Following are the different keyboard :
QWERTY Keyboard
Ergonomic keyboard
Virtual keyboard
Compact keyboard
1.10.2 Pointing Devices 1.10.3 Handheld devices

Pointing Devices : A pointing input device enables the users to


easily control the movement of the pointer to select items on a
display screen, to select commands from commands menu, to draw
graphs, etc. Some examples of pointing devices include mouse,
trackball, light pen, joystick, and touchpad.

Handheld Devices : A handheld device is a pocket-sized computing


device with a display screen and touch input and/or a miniature
keyboard. Some common examples of handheld devices include
smartphones, PDAs, handheld game consoles, and portable media
players (such as iPod).
1.10.4 Optical Devices

Optical Devices : Optical devices, also known as data-scanning


devices
They use light as a source of input for detecting or recognizing
different objects such as characters, marks, codes, and images.
The optical device converts these objects into digital data and
sends it to the computer for further processing.
Some optical devices include barcode readers, image scanners,
optical character recognition (OCR) devices, optical mark readers
(OMR), and magnetic ink character recognition (MICR) devices.
1.10.5 Audio-visual Devices

Audio-visual Input Devices : This type of devices allow user to


read/write text and also enable the user to record songs, view
animated movies, etc.
1.11 Output Devices

Output Devices : Devices that outputs/gives information from a


computer are called an output device.
Basically, output devices are electromechanical devices that
accept digital data (in the form of 0s and 1s) from the computer and
convert them into human-understandable language.
Monitors and speakers are two widely used output devices.
Output devices are classified based on whether they give a hard
copy or soft copy output .
Output Devices

Below diagram show the types of output devices based on the


hard copy and soft copy output
11.1 Soft Copy Devices 11.2 Hard Copy Deices

Soft copy devices :


These devices produce an electronic version of an
output—for example, a file that is stored on a hard disk, CD, or pen
drive—and is displayed on the computer screen.

Hard copy devices :


These devices produce a physical form of output. For
example, the content of a file printed on paper is a form of hard
copy output.
1.12 Programming Paradigms

Programming Paradigms :
 Programming paradigm is the style or way of programming.
 It defines how the programming structure and basic elements of
the computer program will be built.
Each programming paradigm has its own strength and weakness
and no single paradigm can suit all applications.
Different types of programming paradigm are :
Monolithic Programming
Procedural Programming
Structured Programming
Object-oriented Programming (OOP)
1.12.1 Monolithic Programming

Monolithic Programming :
Monolithic programming has only one programming module.
It does not support the concept of subroutines.
This type of programming paradigm consists of global data and
sequential
code.
This type of paradigm focuses/emphasizes on finding only the
solution to
the problem.
All the actions required to complete the task are embedded in one
single
application itself.
Since all the actions are embedded into single application the size
of the program becomes large and becomes difficult to debug and
maintain.
All the instructions are executed in sequence . In order to change
1.12.2 Procedural Programming

Procedural Programming :
In procedure language, the program is divided into subroutines
(functions).
Each subroutine performs a well defined task.
If a subroutine needs a service from another subroutine then the
subroutine can call that subroutine that provides the service.
In procedural programming paradigm the sequence of execution
of the program can be altered.
FOTRON and COBAL are the two popular procedural
programming languages
1.12.3 Structural Programming

Structural Programming :
Structural programming is also called as modular programming.
Structural programming was basically defined to be used in large
programs.
Structural programming employs top-down approach in which
overall program structure divided into modules.
Modules are coded separately and once the module is written and
tested individually .it is then integrated with other modules to form
the overall program structure.
Each modules has its own local data and also use the global data.
Structural programming groups the related logical statements into
modules.
Modularization makes it easy to write, debug and understand the
program.
Modern programming languages such as c and Pascal support the
concept of structural programming
1.12.4 Object Oriented Programming

Object oriented Programming :


In this type of programming paradigm the data and functions are
group into a single entity.
This type of paradigm is task based and data based.
Programs are divided in terms f objects and not procedures.
Function 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
Oop follows bottom-up approach for solving problem.
Day-4

1.13 Example of Structured Programming


1.14 Design and Implementation of Efficient Programs
1.15 Program Design Tools: Algorithms, Flowcharts, Pseudocodes
1.15.1 Algorithms
1.15.2 Control Structures Used in Algorithms
1.15.2 FLOWCHARTS
1.15.3 Pseudocodes
1.16 Types of Errors
1.13 Example of Structured Programming

1.13 Example of Structured Programming


1.14 Design and Implementation of Efficient Programs

The design and development of correct, efficient, and


maintainable programs depends on the approach adopted by the
programmer to perform various activities that need to be performed
during the development process.
The entire program or software (collection of programs)
development process is divided into a number of phases where each
phase performs a well-defined task.
The diagram shows the phases in software
development life cycle
Design and Implementation of Efficient Programs
Requirements Analysis : In this phase all the users expectations
are gathered and all the requirements are analyzed to meet the
objective of the task.
Design : In this phase plan of actions is made before the actual
development process could start. the core structure of the
software/program is broken down into modules. The solution of the
program is then specified for each module in the form of
algorithms, flowcharts, or pseudocodes.
Implementation : In this phase, the designed algorithms are
converted into program code using any of the high level languages.
This phase is also called construction or code generation phase as
Design and Implementation of Efficient Programs
While constructing the code, the development team checks whether
the software is compatible with the available hardware and other
software components that were mentioned in the Requirements
Specification Document created in the first phase.
Testing : In this phase, all the modules are tested together to
ensure that the overall system works well as a whole product. In this
phase, the software is tested using a large number of varied inputs
also known as test data to ensure that the software is working as
expected by the users’ requirements .
Software deployment training and support : In this phase the,
software is installed or deployed into the production environment
Design and Implementation of Efficient Programs
Maintenance : In this phase, if any new problems are identified
in the designed product then the new code is added to fix the
unforeseen problem.
1.15 Program Design Tools
Following are the design tools used to develop the solution for
the given problem:
Algorithms
Control Structures used in algorithm
Flow charts
Pseudo codes
1.15.1 Algorithms
Algorithm:
Algorithm is a step by step procedure used to solve the given
problem with specified set of instructions.
Algorithms are mainly used to achieve software re-use.
In order to qualify as an algorithm, a sequence of instructions must
possess the following characteristics:
 Be precise
 Be unambiguous
 Not even a single instruction must be repeated infinitely
 After the algorithm gets terminated, the desired result must be
obtained
Control Structures used in algorithms
An algorithm can employ any of the three control structures,
namely, sequence, decision, and repetition.
Sequence: Sequence means that each step of the algorithm is
executed in the specified order. An algorithm to add two numbers
. 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.
For example, if x=y, then print “EQUAL”.
Hence, the general form of the if construct can be given as
if condition then process
Control Structures used in algorithms
Repetation : Repetition, which involves executing one or more
steps for a number of times, can be implemented using constructs
such as while, do-while, and for loops.
These loops execute one or more steps until
some condition is true.
the algorithm that prints the first 10 natural numbers.
1.15.3 Flowcharts
Flowcharts : A flowchart is a graphical or symbolic representation
of a process. It is basically used to design and document virtually
complex processes to help the viewers to visualize the logic of the
process.
Following are the symbols used to represent the flowcharts:
Start and end symbols are also known
as the terminal symbols and are
represented as circles, ovals,
or rounded rectangles. Terminal symbols are always the first and
the last symbols in a flowchart.
Arrows depict the flow of control of the program. They illustrate
Flowcharts
Generic processing step, also called as an activity, is represented
using a rectangle. a processing symbol represents arithmetic and
data movement instructions. When more than one process has to be
executed simultaneously, they can be placed in the same processing
box.
Input/output symbols are represented using a parallelogram and
are used to get inputs from the users or display the results to them.
A conditional or decision symbol is represented using a diamond.
It is basically used to depict a Yes/No question or a True/False test.
Labelled connectors are represented by an identifying label inside
a circle and are used in complex or multi- sheet diagrams to
Flowcharts
1.15.4 Pseudocodes
Pseudocodes : are an outline of a program that can be easily
converted into programming statements. They consist of short
English phrases that explain specific tasks within a program’s
algorithm. They should not include keywords in any specific
computer language.
1.16 Types of Errors

While writing programs, very often we get errors in our program.


These errors if not removed will either give erroneous output or will
not let the compiler to compile the program. These errors are
broadly classified under four groups as shown in Figure arrows.

Runtime Errors: these type of errors occur when the program is


being run executed. Such errors occur when the program performs
some illegal operations like
• Dividing a number by zero
• Opening a file that already exists
• Lack of free memory space
Types of Errors
Compile Time Errors: compile-errors occur at the time of
compilation of the program. Such errors can be further classified as
follows:
Syntax Errors: Syntax error is generated when rules of C
programming language are violated. For example, if we write int a:
then a syntax error will occur since the correct statement should be
int a;
Semantic Errors :Semantic errors are those errors which may
comply with rules of the programming language but are not
meaningful to the compiler. For example, if we write, a * b = c; it
does not seem correct. Rather, if written like c = a * b would have
been more meaningful.
Types of Errors

Logic Errors: Logical errors occur due to incorrect statements. For


example, if you meant to perform c = a + b; and by mistake you
typed c = a * b; then though this statement is syntactically correct, it
is logically wrong.

Linker Errors: These errors occur when the linker is not able to find
the function definition for a given prototype. For example, if you
write clrscr(); but do not include conio.h then a linker error will be
shown. Similarly, even if you have defined a function
display_data() but while calling if you mistake and write
displaydata() then again a linker error will be generated.
Day-5

1.17 Testing and Debugging Approaches


1.18 Introduction to C
1.18.1 Characteristics of C
1.18.2 Uses of C
1.19 Structure of a C Program
1.20 Writing the first C Program
1.17 Testing and Debugging Approaches
Testing is performed to verify correct behaviour of a program. It is
specifically carried out with an intent to find errors. Testing should
be conducted at all stages of program development. In the
implementation stage, three types of tests can be conducted:
Unit Test : Unit Tests Unit testing is applied only on a single unit or
module to ensure whether it exhibits the expected behaviour.
Integration Testing : In this test, two units that have already been
tested are combined into a component and the interface between
them is tested.
System Testing :System testing checks the entire system. For
example, if our program code consists of three modules then each
of the module is tested individually using unit tests and then system
Testing and Debugging Approaches
Debugging : The main aim of debugging is locating errors in the
program code. Once the errors are located, they are then isolated
and fixed to produce an error-free code. Different approaches
applied for debugging a code includes:
Brute Force Method : In this technique, a printout of CPU registers
and relevant memory locations is taken, studied, and documented.
Backtracking Method : In this approach first symptom of error is
found and then trace backward across the entire source code until
the real cause of error is detected.
Cause Elimination Method : In this approach, a list of all possible
causes of an error is developed. Then relevant tests are carried out
1.18 Introduction to C

C is a general purpose programming


It is a procedural programming language
C language was developed at AT&T bell labs by Dennis Ritchie
in 1970
C language is the successor of the B Programming language
It was developed to overcome the challenges of BASIC ,B and
BCPL
programming languages.
During 1980 C programming language gained popularity for
creating
mainframes, microcomputers and minicomputers.
1.18.1 Characteristics of C

Following are the characteristics or features of C Language:


Simple and Efficient
Fast
Portability
Extensibility
Functions-Rich libraries
Modularity with structured Programming
Mid-Level Programming Language
Pointers
Recursion
1.18.2 Uses/Application of C

Generally C Language is used to create the following:


Operating Systems
Graphical User Interface
Embedded Systems
Design of a Compilers
Browsers for internet
Development of video games
Mysql (database)
Integrated software libraries for enterprises
Server applications on large scale
and many more…….
1.19 Structure of a C Program

Following shows the structure of C Programming language


Documentation Section
Link Section
Definition Section
Global Declaration Section
main()
{
Declaration part
Execution part
}
// Subprogram section
function1
function 2
.
.
function N
Structure of a C Program

Documentation Section : contains the description of the program,


programmers name and creation date. These are generally written in
the form of comments

Link Section: All header files are included in this section which
contains different functions from the libraries. A copy of these
header files is inserted into your code before compilation.

Definition Section: This section includes preprocessor directive,


which contains symbolic constants. Eg #define allows us to use
constants in our code . It replace all the constants with its value in
the code
Structure of a C Program

Global Declaration Section: this section includes global declaration


of variables, functions and static variables and functions .

main() : For every c program ,the execution starts from the main()
function. It is mandatory to include the main() function in every c
program.

{ : indicates the start of the program

Declaration part: contains any declaration inside the main function.


Execution part: contains group of statements to perform specific
task.
}: indicates the end of the program

Subprogram section: includes user defined functions. User defined


functions can also contain inbuilt functions. User defined functions
1.20 Writing Simple C Program

Below shows the simple C Program


// Write a program to add two numbers
//author: Basavaraj date: 29/11/2022
#include <stdio.h>
#define num1 10
int sum;
void main()
{
int num2 = 20;
sum =summation(num1,num2);
}
void summation( int n1,int n2)
{
sum = n1+n2;
printf(“Sum =%d”,sum);
}
Day-6 Topics

1.21 Files Used in a C Program


1.21.1 Source Code Files
1.21.2 Header Files
1.21.3 Object Files
1.21.4 Binary Executable Files
1.22 Compiling and Executing C Programs
1.23 Using Comments
1.24 C Tokens
1.25 Character Set in C
1.26 Keywords
1.27Identifiers
1.27.1 Rules for Forming Identifier Names
1.28 Basic Data Types in C
1.28.1 How are float and double stored
1.21 Files used in C Program
Source Code File:
This file includes the source code of the program.
The extension for these kind of files are '.c'. It defines the main and
many more functions written in C.
main() is the starting point of the program. It may also contain
other source code files.
Header Files:
They have an extension '.h'. They contain the C function
declarations and macro definitions that are shared between various
source files.
Files used in C Program
Standard header files:
C provides us with some standard header files which are available
easily.
Common standard header files are:
i) string.h – used for handling string functions.
ii) stdlib.h – used for some miscellaneous functions.
iii) stdio.h – used for giving standardized input and output.
iv) math.h – used for mathematical functions.
v) alloc.h – used for dynamic memory allocation.
vi) conio.h – used for clearing the screen.
Files used in C Program
Object files :
They are the files that are generated by the compiler as the source
code file is processed.
These files generally contain the binary code of the function
definitions.
The object file is used by the linker for producing an executable
file for combining the object files together. It has a '.o' extension.
Executable file :
This file is generated by the linker.
Various object files are linked by the linker for producing a
binary file which will be executed directly.
1.22 Compiling and Executing C Programs
1.23 Using Comments
Comments : Comments can be used to explain code, and to make
it more readable. It can also be used to prevent execution when
testing alternative code.

Comments can be singled-lined or multi-lined.

Single-line Comments
Single-line comments start with two forward slashes (//).
Any text between // and the end of the line is ignored by the
compiler (will not be executed).

Example:

//This is a single line comment


Using comments
Multi-line Comments
multi-line comments starts with /* and ends with */
Any text between /* and */ is ignored by the compiler (will not be
executed).

Example:

/* The below lines will print the address of


your college */

printf(“ Yenepoya Institute of Technology \n“);


printf(“ NH-13 Thodar, Moodbidri\n“);
printf(“ Mijar, Dakshin Kannada – Mangalore-74“);
1.24 C Tokens
C Tokens : A token is the smallest unit used in a C program. Each
and every punctuation and word in a C program is token.

Tokens are the building blocks or the very basic components used
in creating any program in the C language.

Tokens are classified as:


Identifiers in C
Keywords in C
Operators in C
Strings in C
Special Characters in C
Constant in C
1.25 Character Sets in C
As every language contains a set of characters used to construct
words, statements, etc., C language also has a set of characters
which include alphabets, digits, and special symbols. C language
supports a total of 256 characters.
Every C program contains statements. These statements are
constructed using words and these words are constructed using
characters from C character set. C language character set contains
the following set of characters...
1.26 Keywords
Keywords: Keywords are the words whose meaning has already
been explained to the compiler This keywords cannot be used as
the name of the variable, name of the function etc…. If we do so
we are trying to assign a new meaning to the keyword, which is not
allowed by the computer.

C programming has 32 keywords.


1.27 Identifiers
Identifiers: These are used to name the arrays, functions,
structures, variables.
The identifiers are user-defined words in the C language.
These can consist of lowercase letters, uppercase letters, digits, or
underscores, but the starting letter should always be either an
alphabet or an underscore.
Example:
age : to store the age of the person
name : to store the name of the person
salary : to store the salary of the employee
sum() : to calculate the sum
1.27.1 Rules to form the Identifiers
The rules for naming identifiers / forming identifiers are as
follows −
Identifier names are unique.
Cannot use a keyword as identifiers.
Identifier has to begin with a letter or underscore (_).
It should not contain white space.
Special characters are not allowed.
Identifiers can consist of only letters, digits, or underscore.
Only 31 characters are significant.
They are case sensitive.
1.28 Basic Data types in C
The basic data types in c programming are:
int
float
char
double
void

Data type : specifies the type and size of data associated with the
variable
Exanple:
int x;

Here x is a variable of type int which stores only the whole


numbers and allocates 4-bytes( 32 bits) of memory.
int data type: Basic Data types in C
1. integers are the whole number that can store both zero, positive
and
negative numbers.
2. integer variables occupy 4- bytes of memory.
3. it can take 2^ 32 distinct states/range from -
2147483648 to 2147483647.
4. integer variables are declared using the keyword int.
5. Example: int accountBalance;
float data type:
1. float are the decimal number that can store real numbers.
2. float variables occupy 4- bytes of memory. 32 bits (IEEE 754
single
precision floating point number ( 1-bit for the sign, 8-bit for
exponent, 23*-
bit for the value. It has 6 decimal digits of precision.
3. float can be represented in exponential form Eg: float m =
22.442e 2
Basic Data types in C
char data type:
1. char data type is going to store a singe character.
2. char variables occupy 1- bytes of memory.
3. it can take 2^ 7 distinct states/range from -128 to 127.
4. char variables are declared using the keyword char.
5. Example: char initial;

double data type:


1. double are the decimal number that can store real numbers.
2. double variables occupy 8- bytes of memory. 64 bits (IEEE 754
single
precision floating point number ( 1-bit for the sign, 11-bit for
exponent,
52*- bit for the value. It has 6 decimal digits of precision.
3. double can be represented in exponential form Eg: double m =
22.442e 2
4. double variables are declared using the keyword double.
Basic Data types in C
void data type:
1. Since the void data type has no meaning, it has no size at all.
2. we usually use void data type with the function, indicating that
function will not return anything

Modifiers: modifiers in C language help in making the primary or


primitive data types much more specific.
Here are a few modifiers:
short
long
unsigned
signed
Just like the names suggest here, we use the unsigned and signed
modifiers for presenting the unsigned (only +) and signed (- and +)
values in any given data type. Also, the short and long modifiers
cause an effect on the value range of any given data type.
Basic Data types and their ranges
Basic Data types and their ranges
1.29 Variable
Definition: Variable is an entity that may vary during program
execution is called a variable.
Variables are the storage locations to hold the values
Variable names (meaningful names) are names given to locations in
memory. These locations can contain integer, real or character
constants.

Example: int principle_Amount, HRA;


float basic_salary, gross_Salary;
char sex ;
1.29 .1 Numeric Variable 1.29 .2 Character Variable

Numeric Variables: Numeric Variables are the variables that can


store the whole numbers and the decimal numbers.
Whole numbers will not have the fraction part while the decimal
numbers have fraction part.
Numeric variables may be associated with short, long, signed and
unsigned modifiers.
In C, by default the numeric is unsigned.
Character Variables: Character variables are the variables that
store the character enclosed in single quotes.
Character can be any alphabets , digits and special symbol
1.29 .3 Declare Variable 1.29 .4 Initialize Variable
Declare Variables: variables can be declared by specifying the
data type and the name of the variable. Declaration of variable
should be terminated with semicolon.
We can declare more than one variable of same type but each
variable should be separated with the comma (,)
Syntax: datatype variable1, variable2,………,variableN;
Example: int sum, salary, age;
Initialize Variables: variables can be initialized using the
assignment operator (=), if variables are not initialized then default
values are assigned.
Synatax: variable = value;
1.30 Constant
Constant: Constant is an entity who's values will not change
during the execution of the program. Constant is declared using the
keyword const.
variables that are declared using const ,trying to change their value
will leads to error.
Constants are classified as :
1.30.1 Integer Constant

Rules for constructing the integer constant:

(a) An integer constant must have at least one digit.


(b) It must not have a decimal point.
(c) It can be either positive or negative.
(d) If no sign precedes an integer constant it is assumed to be
positive.
(e) No commas or blanks are allowed within an integer constant.
(f) The allowable range for integer constants is -32768 to 32767.
(g) Examples: 429, +345,-234, -7894
1.30.2 Floating Point Constant

Rules for constructing the floating point constant:


(a) The mantissa part and the exponential part should be separated by
a letter e.
(b) The mantissa part may have a positive or negative sign.
(c) Default sign of mantissa part is positive.
(d) The exponent must have at least one digit, which must be a
positive or negative integer.
(e) Default sign is positive.
(f) Range of real constants expressed in exponential form is -3.4e38
to 3.4e38.
(g) Ex.: +3.2e-5 4.1e8 -0.2e+3 -3.2e-5
1.30.3 Character Constant
Rules for constructing the Character constant:
(a) A character constant is a single alphabet, a single digit or a single
special symbol enclosed within single inverted commas.
For example, ’A’ is a valid character constant whereas ‘A’ is not.
(b) The maximum length of a character constant can be 1 character.
(c ) Ex.: 'A‘, 'I' , '5‘
1.30.4 String Constant
Rules for constructing String constant:
(a) A string constant is a sequence of alphabet, enclosed within double
inverted commas. For example, “Welcome to C Programming”
1.30.5 Declaring Constant
Declaring the constant
Constants are declared using the keyword const
Syntax: const data type variable = value ;
Example:
const int sem = 1;
const float pi = 3.142;
const char sex = ‘M’;
1.31 Input/output Statements in C
C has no built-in statements for input or output.
A library of functions is supplied to perform these operations The
I/O library
functions are listed the “header” file <stdio.h>
We do not need to memorize the function ,just be familiar with
them.
We can import the library in the program using #include<stdio.h>
Stdio.h library provides many functions such as
printf()
scanf()
fgets()
1.31.1 Streams in C

Streams : Stream is the sequence of characters organized into lines.


All input and output is performed with streams.
Each line consists of zero or more characters and ends with the
“newline”
character.
We have 3 kinds of I/O streams in C:
stdin (standard input)
stdout (standard output)
stderr (standard error)
Standard input stream is called "stdin" and is normally connected to
the
keyboard.
1.31.1 Streams in C

Standard error stream is called "stderr" and is also normally


connected to the
screen.
1.31.2 Formatting Input/output

Formatted Output using printf( ) :


The data stored in the memory can be printed/displayed on the output
device or monitor using the printf() function in C
Syntax:
printf( “formatting-string”, var1,var2,……,varn);

Where
• formatting string is one of the format specifer each format specifer
starts with
%.
•var1,var2,……varn are the values of the variables vr1,var2,
Formatting Input/output
Examples Formatted Output using printf( ) :
Example1:
int a=10,b=20;
printf ( “a=%d and b=%d”, a,b); // output a=10 and b =20

Example2:
float a=12.5;
double b=23.8;
char x = ‘S’;
long int m = 12344567;
printf( “ a= %f \n b=%ld\n x=%c\n m=%ld”, a,b,x,m);
Output:
a=12.500000
b=23.80000000
x= S
m = 12344567
1.31.2 Formatting Input/output
Formatted Input using scanf( ) :
We can store the data into the memory from input devices (such as
keyboard) using the scanf() function in C
Syntax:
scanf( “formatting-string”, &var1,&var2,……,&varn);

Where
• formatting string is one of the format specifer each format specifer
starts with
%.
•&var1,&var2,……&varn are the address of the variables vr1,var2,
Formatting Input/output
Examples Formatted Output using printf( ) :
Example1:
int a=10,b=20;
scanf ( “%d %d”, &a,&b);

Example2:
float a=12.5;
double b=23.8;
char x = ‘S’;
long int m = 12344567;
scanf( “%f%ld%c%ld”, &a,&b,&x,&m);
Thank You

You might also like