100% found this document useful (1 vote)
37 views40 pages

Programming In C EST 102 1st Edition Jayaraj V S All Chapters Instant Download

C

Uploaded by

rosdinboxler
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
37 views40 pages

Programming In C EST 102 1st Edition Jayaraj V S All Chapters Instant Download

C

Uploaded by

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

Download Full Version ebook - Visit ebookmeta.

com

Programming In C EST 102 1st Edition Jayaraj V S

https://ebookmeta.com/product/programming-in-c-est-102-1st-
edition-jayaraj-v-s/

OR CLICK HERE

DOWLOAD NOW

Discover More Ebook - Explore Now at ebookmeta.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

ANALOG INTEGRATED CIRCUITS AND SIMULATION LAB MANUAL


ECL331 1st Edition V S Jayaraj

https://ebookmeta.com/product/analog-integrated-circuits-and-
simulation-lab-manual-ecl331-1st-edition-v-s-jayaraj/

ebookmeta.com

Computer graphics programming in OpenGL with C 2nd


Edition V Scott Gordon

https://ebookmeta.com/product/computer-graphics-programming-in-opengl-
with-c-2nd-edition-v-scott-gordon/

ebookmeta.com

Programming in C Third Edition Kamthane

https://ebookmeta.com/product/programming-in-c-third-edition-kamthane/

ebookmeta.com

Managing Logistics and Transportation in the Public Sector


2nd Edition Darin L. Matthews

https://ebookmeta.com/product/managing-logistics-and-transportation-
in-the-public-sector-2nd-edition-darin-l-matthews/

ebookmeta.com
Introduction to Statistics and Data Analysis: With
Exercises, Solutions and Applications in R, 2nd Edition
Christian Heumann
https://ebookmeta.com/product/introduction-to-statistics-and-data-
analysis-with-exercises-solutions-and-applications-in-r-2nd-edition-
christian-heumann/
ebookmeta.com

Given Bitten and Bound Book 1 1st Edition Amy Pennza

https://ebookmeta.com/product/given-bitten-and-bound-book-1-1st-
edition-amy-pennza-3/

ebookmeta.com

Leveraging Data for Student Success Improving Education


Through Data Driven Decisions 1st Edition Laura G. Knapp

https://ebookmeta.com/product/leveraging-data-for-student-success-
improving-education-through-data-driven-decisions-1st-edition-laura-g-
knapp/
ebookmeta.com

Consultant & Independent Contractor Agreements Tenth


Edition Stephen Fishman J.D.

https://ebookmeta.com/product/consultant-independent-contractor-
agreements-tenth-edition-stephen-fishman-j-d/

ebookmeta.com

The Ghost in the Constitution Historical Memory and Denial


in Spanish Society 1st Edition Joan Ramon Resina

https://ebookmeta.com/product/the-ghost-in-the-constitution-
historical-memory-and-denial-in-spanish-society-1st-edition-joan-
ramon-resina/
ebookmeta.com
The Art of Electronics The x Chapters 3rd Edition Paul
Horowitz

https://ebookmeta.com/product/the-art-of-electronics-the-x-
chapters-3rd-edition-paul-horowitz/

ebookmeta.com
Programming In C
EST-102

As per KTU 2019 syllabus for Semester 2

Jayaraj V S
Sivapriya P M
Programming In C
EST-102

As per KTU 2019 syllabus for Semester 2

Edited By

Jayaraj V S
Sivapriya P M
I would like to dedicate this book
to
My beloved father late Shri R Vamadevan
and
My beloved mother late Smt Sheela Vamadevan
Table of Contents
Preface
About The Editors

Module I
1.1 Basics of Computer Architecture 1

1.1.1 Components of a computer 1


1.1.2 Computing Concepts of a Computer 2

1.1.3 Computer Architecture 3


1.2 System Software and Application Software 6
1.2.1 High-level and Low-level languages 8
1.2.2 Compilers and Interpreters 10
1.3 Introduction to structured approach to programming 12

1.3.1 Algorithm and Flowchart 13

1.3.2 Classification of Algorithms 18


1.3.3 Flowchart definition 19
1.4 Pseudo code 23

1.4.1 Common keywords used in pseudo code 24

1.4.2 Linear search in C 27

1.4.3 Bubble sort in C 30

Module II
Brief History of C Programming Language 35
2.1 Basic structure of C program 38

2.1.1 Character set in C 40


2.1.2 Tokens in C 44
2.1.2.1 Keywords 44
2.1.2.2 Identifiers 45
2.1.2.3 Strings in C 46
2.1.2.4 Operators in C 46
2.1.3 C Variable, Data types, Constants 47
2.1.3.1 Variable 47
2.1.3.2 Data types 48
2.1.3.2.1 Integer data type 49
2.1.3.2.2 Floating point data type 49
2.1.3.2.3 Character data type 49
2.1.3.2.4 Void data type 50
2.1.3.3 Constants 50
2.1.3.3.1 Integer constants 50
2.1.3.3.2 Character constants 50
2.1.3.3.3 String constants 51
2.1.3.3.4 Real Constants 51
2.1.4 Console Input/output Operations: printf() and scanf() 51

2.2 Operators and Expressions 57


2.2.1 Arithmetic Operators 57
2.2.2 Relational Operators 58

2.2.3 Logical Operators 60


2.2.4 Bitwise Operators 61
2.2.5 Assignment Operator 62
2.2.6 Misc Operator 63
2.2.6.1 Sizeof Operator in C 64
2.2.6.2 Conditional Expression (Ternary operator) 65
2.2.7 Precedence of operators 66
2.3 Control Flow Statements 68
2.3.1 Branching 69
2.3.1.1 If Statement 69
2.3.1.2 If-else statement 72
2.3.1.3 If else-if ladder 73
2.3.1.4 Nested if 75
2.3.2 C Switch Statement 77
2.3.3 Unconditional Branching using goto statement 80

2.3.4 C Loops 82
2.3.4.1 do-while loop in C 83
2.3.4.2 While loop in C 84
2.3.4.2.1 Infinitive while loop in C 86
2.3.4.3 For loop in C 87
2.3.4.3.1 Loop expressions For loop 88
2.3.4.3.2 Infinitive for loop in C 92
2.3.5 Break and Continue statements 92
2.3.5.1 C break 92
2.3.5.2 C Continue 93

2.3.6 Simple C programs 95

Module III

3.1 Arrays Declaration and Initialization 102


3.1.1 Declaration of Array in C 103
3.1.2 Initialization of C Array 103

3.1.3 C Array: Declaration with Initialization 104


3.1.4 Two-Dimensional Array in C 106
3.1.4.1 Declaration of two-dimensional Array in C 106
3.1.4.2 Initialization of 2D Array in C 107
3.2 String processing 109
3.2.1 Difference between char array and string literal 109
3.2.2 How to initialize strings? 109
3.2.3 Traversing String 110

3.2.4 Accepting string as the input 112


3.3 String handling functions 113

3.3.1 C String Length: strlen() function 113


3.3.2 C String Copy: strcpy () function 114
3.3.3 C String Concatenation: strcat () function 115
3.3.4 C String Comparison: strcmp () function 116
3.2.5 C gets() and puts() functions 117
3.2.5.1 C gets() function 117
3.2.5.2 C puts() function 119
3.4 Linear search and Bubble sort program, simple programs covering arrays 119
and strings
3.4.1 Linear Search Program to search an element in an array 119
3.4.2 Bubble sort Program to sort elements in an array 121
3.4.3 Simple programs covering arrays and strings 123

Module IV
4.1 Working with functions 145
4.1.1 Functions in C 145
4.1.2 Types of function 146
4.1.2.1 Standard library functions 146
4.1.2.2 User-defined function 147
4.1.3 Working of a function in C 147
4.1.4 Declaration / Defining a function 148
4.1.5 Calling a function 149
4.1.6 Example of a User-defined function 149
4.1.7 Different aspects of function calling in C 150
4.1.7.1 Function without arguments and without return value 150
4.1.7.2 Function without arguments and with return value 151
4.1.7.3 Function with arguments and without return value 152
4.1.7.4 Function with arguments and with return value 153
4.1.8 Actual and Formal arguments in C 154
4.1.8.1 Actual arguments 154
4.1.8.2 Formal Arguments 154
4.2 Working with functions continued 156
4.2.1 Call by value in C 156
4.2.1.1 Call by Value Example: Swapping the values of the 156
two variables
4.2.2 Recursion in C 157
4.2.2.1 Recursion function 157
4.2.2.2 How recursion works? 158
4.2.3 Arrays as Function Parameters / Passing arrays as parameter to 161
function
4.2.3.1 Passing a single array element to a function 161
4.2.3.2 Passing a complete One-dimensional array to a 162
function
4.2.3.3 Passing a Multi-dimensional array to a function 163
4.2.3.4 More Examples 164
4.3 Working with functions continued 166
4.3.1 C Structure 166
4.3.1.1 Defining a structure in C 166
4.3.1.2 Declaring Structure Variables 167
4.3.1.3 Accessing Structure Members 167
4.3.1.4 Structure Initialization 169
4.3.1.5 Array of Structure 170
4.3.1.6 Nested Structures 173
4.3.1.7 typedef in C 176
4.3.1.7.1 Structure definition using typedef 177
4.3.2 C Union 179
4.3.2.1 Defining union 179
4.3.2.2 Create union variables 180
4.3.2.3 Difference between structures and unions 182
4.3.2.4 Accessing Union Members 184
4.3.2.5 Comparing Structures and unions 185
4.3.3 Storage Classes in C 186
4.3.3.1 The auto Storage Class 187
4.3.3.2 The extern Storage Class 188
4.3.3.3 The static Storage Class 189
4.3.3.4 The register Storage Class 190
4.3.4 Scope and life time of variables 190
4.3.5 Simple programs using functions 191

Module V
5.1 Basics of Pointer 205
5.1.1 What is Pointer in C Programming? 205
5.1.2 Declaring a pointer 205
5.1.2.1 Pointer to integer, double, character, float 205
5.1.2.2 Pointer to array 206
5.1.2.3 Pointer to a function 206
5.1.3 Advantages of pointer 206
5.1.4 Usage of pointer 206
5.1.5 Address Of (&) Operator 206
5.1.6 NULL Pointer 207
5.1.7 Working of Pointers 207
5.1.7.1 Pointer Example: Assigning addresses to Pointers 207
5.1.7.2 Pointer Example: Get Value of Thing Pointed by 208
Pointers
5.1.7.3 Pointer Example: Changing Value Pointed by 208
Pointers
5.1.7.4 Pointer Example: Using pointers to print the address 209
and value
5.1.7.5 Pointer Example: Working of Pointers 210
5.1.8 Common mistakes when working with pointers 210
5.1.9 Arrays and Pointers 211
5.1.9.1 Relationship Between Arrays and Pointers 211
5.1.9.2 Pointer to an Array in C 214
5.1.9.3 Arrays of Pointers in C 215
5.1.9.4 Sample programs demonstrating Working of 215
Pointers
5.1.10 Call by reference in C 220
5.1.11 Dynamic memory allocation in C 221
5.1.11.1 malloc() 222
5.1.11.2 calloc() 222
5.1.11.3 realloc() 222
5.1.11.4 free() 222
5.2 File Operations 226
5.2.1 Introduction to File Handling 226
5.2.2 C File Operations 227
5.2.2.1 Opening a file 227
5.2.2.2 Reading a File 228
5.2.2.3 Writing to a file 230
5.2.2.4 Closing a file: fclose() 232
5.2.2.5 Appending a file 232
5.2.3 Reading and writing to a binary file 233
5.2.3.1 Writing to a binary file 233
5.2.3.2 Reading from a binary file 234
5.2.3.3 Appending to a binary file 235
5.3 Sequential access and random access to files 237
5.3.1 What is Sequential Access? 237
5.3.2 What is Random Access? 237
5.3.3 Advantages of Sequential access and random access to files 237
5.3.4 Random access/Direct access files 237
5.3.5 C fseek() function 237
5.3.6 C rewind() function 240
5.3.7 C ftell() function 240
5.3.8 feof() function 241
5.3.9 Simple programs covering pointers and files 242

251
C PROGRAMMING LAB
LIST OF LAB EXPERIMENTS 252
1 Familiarization of Hardware Components of a Computer 254
2 Familiarization of Linux environment – How to do Programming in C with 256
Linux
3 Familiarization of console I/O and operators in C 261
i) Display “Hello World”
ii) Read two numbers, add them and display their sum
iii) Read the radius of a circle, calculate its area and display it
iv) Evaluate the arithmetic expression ((a -b / c * d + e) * (f +g)) and
display its solution. Read the values of the variables from the user
through console.
4 Read 3 integer values and find the largest among them. 263
5 Read a Natural Number and check whether the number is prime or not. 263
6 Read a Natural Number and check whether the number is Armstrong or not. 264
7 Read n integers, store them in an array and find their sum and average. 265
8 Read n integers, store them in an array and search for an element in the 267
array using an algorithm for Linear Search.
9 Read n integers, store them in an array and sort the elements in the array using 268
Bubble Sort algorithm.
10 Read a string (word), store it in an array and check whether it is a palindrome 270
word or not.
11 Read two strings (each one ending with a $ symbol), store them in arrays and 271
concatenate them without using library functions.
12 Read a string (ending with a $ symbol), store it in an array and count the 272
number of vowels, consonants and spaces in it.
13 Read two input each representing the distances between two points in the 273
Euclidean space, store these in structure variables and add the two distance
values.
14 Using structure, read and print data of n employees (Name, Employee Id and 274
Salary).
15 Declare a union containing 5 string variables (Name, House Name, City 276
Name, State and Pin code) each with a length of C_SIZE (user defined
constant). Then, read and display the address of a person using a variable of
the union.
16 Find the factorial of a given Natural Number n using recursive and non- 277
recursive functions.
17 Read a string (word), store it in an array and obtain its reverse by using a user 279
defined function.
18 Write a menu driven program for performing matrix addition, multiplication 280
and finding the transpose.
Use functions to
(i) Read a matrix.
(ii) Find the sum of two matrices.
(iii) Find the product of two matrices.
(iv) Find the transpose of a matrix
(v) Display a matrix.
19 Do the following using pointers 284
i) add two numbers
ii) swap two numbers using a user defined function
20 Input and print the elements of an array using pointers. 286
21 Compute sum of the elements stored in an array using pointers and user 287
defined function.
22 Create a file and perform the following 288
i) Write data to the file
ii) Read the data in a given file & display the file content on
console
iii) Append new data and display on console
23 Open a text input file and count number of characters, words and lines in it; 289
and store the results in an output file.

Bibliography
Preface
This book is intended for all aspirants who would like to begin exploring their programming
skills with C. C is currently the premier language for software developers as it’s widely
distributed and standardized. Newer languages are available, such as Python, Java, R etc. but
still C is the language of choice for robust and portable programming. This is because System
level programming and Embedded system programming still dependent on C.
This book emphasizes the basic skills one requires to solve real-world programming problems.
It teaches you not only the mechanics of the C language, but helps you to understand the
concepts clearly with usage of different color shades in code presentation and explanation.
In order to bridge the gap between theory and practical, each concept is explained at length in
an easy-to-understand manner supported with numerous worked-out examples and programs.
The Codes presented in this book are compiled and run-on Visual Studio Code. Visual Studio
Code is a lightweight but powerful source code editor which runs on your desktop and is
available for Windows, macOS and Linux. It comes with a rich ecosystem of extensions for
languages (such as C++, C#, Java, Python, PHP, Go). Using Visual Studio Code would help a
beginner to visually understand and rectify the errors while coding.
Anybody can write a code, but real skill lies in the way a code is written and presented. So, to
create a good program, one must do more than just type in a code. It is always expected from
a programmer to blend both writing and programming skills together to form a simple, readable
and easy to understand Code.
Book Organization
As this book is edited as per the KTU syllabus, it is organized into two parts:
i) Module by Module
Module-I: Gives a basic understanding of computer components and its
architecture along with best method of writing algorithms and drawing of flowchart.
It also describes the writing of Pseudo code.
Module-II: Gives a basic understanding of the structure of a C program, Operators
and Expressions and also in detail the programming with Control Flow Statements.
Module-III: Gives a detail understanding of Arrays and Strings along with
programs covering arrays and strings.
Module-IV: Introduces to modular programming, Functions, Recursion, Arrays as
Function Parameters, Structure, Union, Storage Classes, Scope and life time of
variables.
Module-V: Introduces to Basics of Pointers, File Operations in C, Sequential
access and Random access to files.
ii) Lab Programs
A list of 23 programs as per the syllabus is provided to give the students a better
hand on session with topics learned from modules in part one.

As editors of this book, we are very delighted to present the First Edition of Programming in
C, which is free and can be downloaded from jayarajvamadevan (Jayaraj Vamadevan) · GitHub .
We have tried to make this book Student friendly by using simple and lucid language.
We hope both student community and teaching fraternity are benefitted by our book.

Jayaraj V S
Sivapriya P M
About The Editors
Jayaraj V S did his BE in Electronics & Communication Engineering in 2005
from Mohammed Sathak Engineering College, Kilakarai and ME in
Communication Systems in 2007 from Mepco Schlenk Engineering College,
Sivakasi. Currently working as a faculty of Sree Buddha College of Engineering,
Pattoor.

Sivapriya P M did her BTech in Computer Science in 2009 from Government


Engineering College Palakkad, Sreekrishnapuram. Currently working with the
Department of Post Government of India.
MODULE BY MODULE
(Theory part of EST 102, Programming in C)
Module-I

Basics of Computer Hardware and Software


1.1 Basics of Computer Architecture: Processor, Memory, Input& Output devices

1.2 Application Software & System software: Compilers, interpreters, High level and
low-level languages
1.3 Introduction to structured approach to programming, Flow chart
1.4 Algorithms, Pseudo code (bubble sort, linear search - algorithms and pseudo code)

1.1 Basics of Computer Architecture


What is a computer?
“A computer is an electronic machine that takes input from the user, processes the
given input and generates output in the form of useful information”
A computer accepts input in different forms such as data, programs and user reply.
 Data refer to the raw details that need to be processed to generate some useful
information.
 Programs refer to the set of instructions that can be executed by the computer in
sequential or non-sequential manner.
 User reply is the input provided by the user in response to a question asked by the
computer.
The main task of a computer system is to process the given input of any type in an efficient
manner. Therefore, computer is also known by various other names such as data processing
unit, data processor and data processing system.
1.1.1 Components of a computer
Computer includes various devices that function as an integrated system to perform several
tasks described above.
These devices are:
1) Central Processing Unit (CPU)
It is the processor of the computer that is responsible for controlling and executing
instructions in the computer. It is considered as the most significant component of the
computer. It is the “brain” of the computer.

1
2) Monitor
It is a screen, which displays information in visual form, after receiving the video signals
from the computer.
3) Keyboard and Mouse
These are the devices, which are used by the computer, for receiving input from the user.

The components of a computer

1.1.2 Computing Concepts of a Computer


We can understand how a computer functions by analysing the fundamental computing
concepts. The most elementary computing concepts include receiving input known as data
from the user, manipulating the input according to the given set of instructions and delivering
the output known as information to the user. Figure below shows the functioning of a
computer based on these concepts.

The Input-Process-Output Cycle of a computer

2
The various functions performed by the computer are briefly described below:
a) Accepting the raw data
The first task to be performed by a computer is to accept the data from the user, with the help
of an input device, such as mouse and keyboard. Mouse is used to enter the data through
point-and-click operation while keyboard is used to enter the character data by typing the
various keys.
b) Processing the data
The data is processed with the help of specific instructions known as programs after taking
the input from the user. The manipulation of data is handled by the CPU of the computer.
CPU is considered as the brain of the computer because it controls the execution of various
instructions. The raw data entered by the user through input devices is processed by the CPU
to generate meaningful information.
c) Storing the data
The data is stored in the main memory of a computer in its processed form. The various
external storage devices—such as hard disk and magnetic disk—can also be used for storing
the processed data so that it can again be fetched later.
d) Delivering the output
The processed data is delivered as useful information to the user with the help of output
devices, such as printer and monitor.
1.1.3 Computer Architecture
Computer architecture is a science or a set of rules stating how computer software and
hardware join and interact to make a computer work. The architecture basically defines the
logical structure of a computer system.
Historically there have been 2 types of Computers:
a) Fixed Program Computers – Their function is very specific, and they couldn’t be
programmed, e.g., Calculators.
b) Stored Program Computers – These can be programmed to carry out many different
tasks, applications are stored on them, hence the name.
The modern computer is based on a stored-program concept introduced by John Von
Neumann and has three basic units.
 The Central Processing Unit (CPU)
 Memory Unit
 The Input / Output Unit

3
Von Neumann Architecture
1) The Central Processing Unit (CPU)
A Central Processing Unit is also called a processor, central processor, or microprocessor. It
carries out all the important functions of a computer. It receives instructions from both the
hardware and active software and produces output accordingly. It stores all important
programs like operating systems and application software.
CPU also helps Input and output devices to communicate with each other. Owing to these
features of CPU, it is often referred to as the brain of the computer.
CPU is installed or inserted into a CPU socket located on the motherboard. Furthermore, it is
provided with a heat sink to absorb and dissipate heat to keep the CPU cool and functioning
smoothly.
It basically has three main units:
a) Arithmetic and Logic Unit (ALU)
b) Control Unit
c) Main Memory Unit (Registers)
a) Arithmetic and Logic Unit (ALU)
It is the arithmetic logic unit, which performs arithmetic and logical functions. Arithmetic
functions include addition, subtraction, multiplication division, and comparisons. Logical
functions mainly include selecting, comparing, and merging the data. A CPU may contain
more than one ALU. Furthermore, ALUs can be used for maintaining timers that help run the
computer.

4
b) Control Unit
It is the circuitry in the control unit, which makes use of electrical signals to instruct the
computer system for executing already stored instructions. It takes instructions from memory
and then decodes and executes these instructions. So, it controls and coordinates the
functioning of all parts of the computer. The Control Unit's main task is to maintain and
regulate the flow of information across the processor. It does not take part in processing and
storing data.
c) Main Memory Unit (Registers)
 Accumulator: Stores the results of calculations made by ALU.
 Program Counter (PC): Keeps track of the memory location of the next
instructions to be dealt with. The PC then passes this next address to
Memory Address Register (MAR).
 Memory Address Register (MAR): It stores the memory locations of
instructions that need to be fetched from memory or stored into memory.
 Memory Data Register (MDR): It stores instructions fetched from memory
or any data that is to be transferred to, and stored in, memory.
 Current Instruction Register (CIR): It stores the most recently fetched
instructions while it is waiting to be coded and executed.
 Instruction Buffer Register (IBR): The instruction that is not to be
executed immediately is placed in the instruction buffer register IBR.
2) Memory Unit
Computer memory is any physical device capable of storing information temporarily, like
RAM (random access memory), or permanently, like ROM (read-only memory).
Memories can be classified into two categories:
 Primary Memory
 Secondary Memory
a) Primary memory is computer memory that is accessed directly by the CPU. There are
two types of primary memory.
 Read Only Memory (ROM)
 Random Access Memory (RAM)
ROM: The content of it cannot be changed and can be used only by CPU. It is needed to
store Basic Input Output System (BIOS), which is responsible for booting. This memory is
permanent in storage (non-volatile) and is very small in size.

5
RAM: It is a volatile memory i.e.; its contents get destroyed as soon as the computers is
switched off. All kinds of processing of CPU are done in this memory.
b) Secondary Memory
Primary memory has limited storage capacity and is volatile. Secondary memory overcomes
this limitation by providing permanent storage of data and in bulk quantity. Secondary
memory is also termed as external memory and refers to the various storage media on which
a computer can store data and programs. The Secondary storage media can be fixed or
removable. Fixed Storage media is an internal storage medium like hard disk that is fixed
inside the computer. Storage medium that are portable and can be taken outside the computer
are termed as removable storage media.
Example: Hard disk, Magnetic Tapes, Pen drive.
3) Input /Output Unit
The input/output unit consists of devices used to transmit information between the external
world and computer memory. The information fed through the input unit is stored in
computer memory for processing and the result stored in memory can be recorded or display
on the output medium.
Example: Mouse, Keyboard, Printer, Monitor, etc.

1.2 System Software and Application Software


Software is a set of programs, which is designed to perform a well-defined function. A
program is a sequence of instructions written to solve a particular problem.
There are two types of software –
 System Software
 Application Software
a) System Software
The system software is a collection of programs designed to operate, control, and extend the
processing capabilities of the computer itself. System software is generally prepared by the
computer manufacturers. These software products comprise of programs written in low-level
languages, which interact with the hardware at a very basic level. System software serves as
the interface between the hardware and the end users.
Examples - Operating System, Compilers, Interpreter, Assemblers, etc.
Some of the most prominent features of system software −
 Close to the system
 Fast in speed

6
 Difficult to design
 Difficult to understand
 Less interactive
 Smaller in size
 Difficult to manipulate
 Generally written in low-level language
b) Application Software
Application software products are designed to satisfy a particular need of a particular
environment. All software applications prepared in the computer lab can come under the
category of Application software.
Application software may consist of a single program, such as Microsoft's notepad for
writing and editing a simple text. It may also consist of a collection of programs, often called
a software package, which work together to accomplish a task, such as MS Office.
Examples − Railways Reservation Software, Microsoft Office Suite Software, Microsoft
Word, Microsoft Excel, Microsoft PowerPoint.
Some of the most prominent features of application software are as follows −
 Close to the user
 Easy to design
 More interactive
 Slow in speed
 Generally written in high-level language
 Easy to understand
 Easy to manipulate and use
 Bigger in size and requires large storage space

S.no System software Application software


System Software maintains the Application software is built for specific
1 system resources and gives the path tasks.
for application software to run.
Low level languages are used to High level languages are used to write the
2 write the system software. application software.

Machine Dependent Machine independent


3

4 It is general-purpose software. It is specific purpose software.

7
Without system software, system Without application software system always
5 can’t run. runs.
System software runs when system While application software runs as per the
6 is turned on and when system is user’s request.
turned off.
Compiler, Operating System, Photoshop, Microsoft Office, VLC
7 Interpreter

1.2.1 High-level and Low-level languages


What is a programming language?
A programming language defines a set of instructions that are compiled together to perform a
specific task by the CPU (Central Processing Unit). The programming language mainly refers
to high-level languages such as C, C++, Pascal, COBOL, etc.
Basically, there are two main categories of computer languages, namely Low-Level
Language and High-Level Language.
1) Low Level Languages
Low level languages are the basic computer instructions or better known as machine codes. A
computer cannot understand any instruction given to it by the user in English or any other
high-level language. These low-level languages are very easily understandable by the
machine.
The main function of low-level languages is to interact with the hardware of the computer.
They help in operating, syncing, and managing all the hardware and system components of
the computer. They handle all the instructions which form the architecture of the hardware
systems.
a) Machine Language
This is one of the most basic low-level languages. The language was first developed to
interact with the first-generation computers. It is written in binary code or machine code,
which means it basically comprises of only two digits – 1 and 0.
b) Assembly Language
This is the second-generation programming language. It is a development on the machine
language, where instead of using only numbers, we use English words, names, and symbols.
It is the most basic computer language necessary for any processor.
2) High Level Language
When we talk about high level languages, these are programming languages. Some prominent
examples are PASCAL, FORTRAN, C++ etc.

8
The important feature about such high-level languages is that they allow the programmer to
write programs for all types of computers and systems. Every instruction in high level
language is converted to machine language for the computer to comprehend.
a) Scripting Languages
Scripting languages or scripts are essentially programming languages. These languages
employ a high-level construct which allows it to interpret and execute one command at a
time.
Scripting languages are easier to learn and execute than compiled languages. Some examples
are AppleScript, JavaScript, Pearl etc.
b) Object-Oriented Languages
These are high level languages that focus on the ‘objects’ rather than the ‘actions. To
accomplish this, the focus will be on data than logic.
The reasoning behind is that the programmers really care about the object they wish to
manipulate rather than the logic needed to manipulate them. Some examples include Java,
C+, C++, Python, Swift etc.
c) Procedural Programming Language
This is a type of programming language that has well-structured steps and complex
procedures within its programming to compose a complete program.
It has a systematic order functions and commands to complete a task or a program. C,
FORTRAN, ALGOL, BASIC, COBOL is some examples.

High level Vs Low level language

Low-level language High-level language

It is a machine-friendly language, It is a user-friendly language as this language is


i.e., the computer understands the written in simple English words, which can be
machine language, which is easily understood by humans.
represented in 0 or 1.

The low-level language takes more It executes at a faster pace.


time to execute.

It requires the assembler to convert It requires the compiler to convert the high-level
the assembly code into machine language instructions into machine code.
code.

9
The machine code cannot run on all The high-level code can run all the platforms, so it
machines, so it is not a portable is a portable language.
language.

It is memory efficient. It is less memory efficient.

Debugging and maintenance are not Debugging and maintenance are easier in a high-
easier in a low-level language. level language.

1.2.2 Compilers and Interpreters


a) Interpreter
In computer terms, the programming interpreter reads the first line of the code, interprets it
into machine code and sends it to the CPU to be processed. It then interprets the next line and
sends that to the CPU, and so on. By interpreting the program line by line, the program can
immediately start running. However, since every line needs to be interpreted before it can
run, the program will often run a bit more slowly than a compiled program. The source code
is interpreted as the program is run; the interpreter (and interpreted language) must be
installed on the same computer that the program is running. The examples of an interpreted
language are JavaScript, Python 2, and Python 3.
b) Compiler
In contrast to an interpreter, the compiler takes the entire source code and translates it into
machine code. This translated code is saved as an executable file on the computer that can be
opened on any computer without requiring the computer to have a compiler. Examples of
compiled languages include BASIC, C, C++, Delphi, and Java.
Compilation process of C programming passes through following stages before being
transformed into an executable form:
 Pre-processor
 Compiler
 Assembler
 Linker
Pre-processor: The source code is the code which is written in a text editor and the source
code file is given an extension ".c". This source code is first passed to the pre-processor, and
then the pre-processor expands this code. After expanding the code, the expanded code is
passed to the compiler.

10
Compiler: The code which is expanded by the pre-processor is passed to the compiler. The
compiler converts this code into assembly code. Or we can say that the C compiler converts
the pre-processed code into assembly code.
Assembler: The assembly code is converted into object code by using an assembler. The
name of the object file generated by the assembler is the same as the source file. The
extension of the object file in DOS is '.obj. If the name of the source file is 'hello.c', then the
name of the object file would be 'hello.obj'.
Linker: Mainly, all the programs written in C use library functions. These library functions
are pre-compiled, and the object code of these library files is stored with '.lib' (or ‘. a')
extension. The main working of the linker is to combine the object code of library files with
the object code of our program. The output of the linker is the executable file. The name of
the executable file is the same as the source file but differs only in their extensions. In DOS,
the extension of the executable file is '.exe'. For example, if we are using printf () function in
a program, then the linker adds its associated code in an output file.

Compiler Vs Interpreter
Basis of
Compiler Interpreter
comparison
A compiler converts high-level Interpreter converts source code into
language program code into the intermediate form and then
Function
machine language and then converts that intermediate code into
executes it. machine language

11
Complier scans the entire Interpreter scans and translates the
Scanning program first before translating program line by line to equivalent
into machine code. machine code.
Compiler takes entire program Interpreter takes single instruction as
Working
as input. input.
Code Intermediate object code is In case of interpreter, no intermediate
Generation generated in case of compiler. object code is generated.
Compiler takes less execution
Execution Interpreter takes more execution time
time when compared to
Time when compared to compiler.
interpreter.

Memory Compiler requires more memory Interpreter needs less memory when
Requirement than interpreter. compared to compiler.
If you happen to make any
modification in program you If you make any modification and if
have to recompile entire that line has not been scanned, then
Modification
program i.e., scan the whole no need to recompile entire program.
program every time after
modification.

Compiler is faster when Interpreter is slower when compared


Speed
compared to interpreter. to compiler.

There is usually no need to


Every time program is scanned and
At Execution compile program every time (if
translated at execution time.
not modified) at execution time.
Compiler gives you the list of all Interpreter stops the translation at the
Error errors after compilation of whole error generation and will continue
Detection
program. when error get solved.
Compiler is slow for debugging
because errors are displayed Interpreter is good for fast
Debugging
after entire program has been debugging.
checked.

Examples C, COBOL, C#, C++, etc Python, VB, Java Script etc.

1.3 Introduction to structured approach to programming


Structured Programming Approach, as the word suggests, can be defined as a
programming approach in which the program is made as a single structure. It means that the
code will execute the instruction by instruction one after the other. It doesn’t support the
possibility of jumping from one instruction to some other with the help of any statement like

12
GOTO, etc. Therefore, the instructions in this approach will be executed in a serial and
structured manner.
The structured program mainly consists of three types of elements:
 Selection Statements
 Sequence Statements
 Iteration Statements
The structured program consists of well-structured and separated modules. But the entry and
exit in a structured program is a single-time event. It means that the program uses single-
entry and single-exit elements. Therefore, a structured program is well maintained, neat and
clean program. This is the reason why the Structured Programming Approach is well
accepted in the programming world.
Advantages of Structured Programming Approach:
 Easier to read and understand
 User Friendly
 Easier to Maintain
 Mainly problem based instead of being machine based
 Development is easier as it requires less effort and time
 Easier to Debug
 Machine-Independent, mostly.
Disadvantages of Structured Programming Approach:
1. Since it is Machine-Independent, so it takes time to convert into machine code.
2. The converted machine code is not the same as for assembly language.
3. The program depends upon changeable factors like datatypes. Therefore, it needs to be
updated with the need on the go.
4. Usually, the development in this approach takes longer time as it is language dependent.
Whereas in the case of assembly language, the development takes lesser time as it is
fixed for the machine.

1.3.1 Algorithm and Flowchart


Algorithm definition-In programming, algorithm is a set of well-defined instructions in
sequence to solve the problem.
Qualities of a good algorithm
 Input and output should be defined precisely.
 Each step-in algorithm should be clear and understandable.

13
 Algorithm should be most effective among many ways to solve a problem.
 An algorithm shouldn’t have computer code. Instead, the algorithm should be written
in such a way that, it can be used in similar programming languages.
Examples of Algorithms in Programming
1) Write an algorithm to add two numbers entered by user.

Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop
2) Write an algorithm to find the largest among three different numbers entered by
user.

Step 1: Start
Start 2: Input a, b, c
Start 3: If a > b goto step 4, otherwise goto step 5
Start 4: If a > c goto step 6, otherwise goto step 8
Start 5: if b > c goto step 7, otherwise goto step 8
Start 6: Output "a is the largest", goto step 9
Start 7: Output "b is the largest", goto step 9
Start 8: Output " c is the largest", goto step 9
Start 9: Stop
3) Finding Area of the square
Step 1: Start
Step 2: Declare the variables length and area.
Step 3: Read the value of length.
Step 4: Multiply length and length and assign the result to area.
area← length * length
Step 5: Display area
Step 6: Stop

14
4) Finding Area of a square with 3 different sides
Step 1: Start
Step 2: Declare the variables a, b, c, s and Area.
Step 3: Read the value of a, b and c.
Step 4: Compute semi-perimeter and assign the value to s
s← (a + b + c)/2
Step 4: Compute the area and assign the result to Area
Area← sqrt(s(s-a) (s-b) (s-c))
Step 5: Display Area
Step 6: Stop
5) Calculating the average for 3 numbers
Step 1: Start
Step 2: Declare variables num1, num2, num3 and Average.
Step 3: Read values num1, num2, and num3.
Step 4: Add num1, num2 and num3 and divide by 3 then assign the result to Average.
Average←(num1+num2+num3) /2
Step 5: Display Average.
Step 6: Stop
6) Greatest of two numbers
Step 1: Start
Step 2: Declare variables A and B
Step 3: Read values of A and B
Step 4: If A ≥ B
Display A is greater than B.
Else
Display B is greater than A.
Step 5: Stop
7) Find Root of the quadratic equation ax2 + bx + c = 0
Step 1: Start
Step 2: Declare variables a, b, c, D, r1, r2, rp and ip
Step 3: Read values of a, b and c.
Step 4: Calculate discriminant and assign the value to D
D ← b2-4ac
Step 4: If D ≥ 0

15
Calculate r1and r2
r1 ← (-b+√D)/2a
r2 ← (-b-√D)/2a
Display r1 and r2 as roots.
Else
Calculate real part and imaginary part
rp ← -b/2a
ip ← √(-D)/2a
Display rp + j(ip) and rp - j(ip) as roots
Step 5: Stop
8) Interchange the value of two numbers
Step 1: Start
Step 2: Declare variables a, b and c
Step 3: Read the value of a and b
Step 3: Perform Swapping of value as
c =a
a=b
b=c
Step 4: Display the value of a and b
Step 5: Stop
9) Find the factorial of a number
Step 1: Start
Step 2: Declare variables F, N and i
Step 3: Initialize the value of F=1 and i=1
Step 4: Read the value of N
Step 5: Multiply F with i and assign the vale to F
F=F*i
Step 6: Increment i by 1
Step 7: Repeat step 5 & 6 until i = N
Step 8: Display the value of F
Step 9: Stop
10) Find the Sum of Natural Numbers till N
Step 1: Start
Step 2: Declare variables count, N and sum

16
Discovering Diverse Content Through
Random Scribd Documents
property infringement, a defective or damaged disk or other
medium, a computer virus, or computer codes that damage or
cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES -


Except for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU
AGREE THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE,
STRICT LIABILITY, BREACH OF WARRANTY OR BREACH
OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE
TRADEMARK OWNER, AND ANY DISTRIBUTOR UNDER
THIS AGREEMENT WILL NOT BE LIABLE TO YOU FOR
ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE
OR INCIDENTAL DAMAGES EVEN IF YOU GIVE NOTICE OF
THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If


you discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person or
entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR
ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you do
or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission of


Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.
Volunteers and financial support to provide volunteers with the
assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status by
the Internal Revenue Service. The Foundation’s EIN or federal
tax identification number is 64-6221541. Contributions to the
Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or
determine the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About Project


Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.

You might also like