Programming In C EST 102 1st Edition Jayaraj V S All Chapters Instant Download
Programming In C EST 102 1st Edition Jayaraj V S All Chapters Instant Download
com
https://ebookmeta.com/product/programming-in-c-est-102-1st-
edition-jayaraj-v-s/
OR CLICK HERE
DOWLOAD NOW
https://ebookmeta.com/product/analog-integrated-circuits-and-
simulation-lab-manual-ecl331-1st-edition-v-s-jayaraj/
ebookmeta.com
https://ebookmeta.com/product/computer-graphics-programming-in-opengl-
with-c-2nd-edition-v-scott-gordon/
ebookmeta.com
https://ebookmeta.com/product/programming-in-c-third-edition-kamthane/
ebookmeta.com
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
https://ebookmeta.com/product/given-bitten-and-bound-book-1-1st-
edition-amy-pennza-3/
ebookmeta.com
https://ebookmeta.com/product/leveraging-data-for-student-success-
improving-education-through-data-driven-decisions-1st-edition-laura-g-
knapp/
ebookmeta.com
https://ebookmeta.com/product/consultant-independent-contractor-
agreements-tenth-edition-stephen-fishman-j-d/
ebookmeta.com
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
Jayaraj V S
Sivapriya P M
Programming In C
EST-102
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
Module II
Brief History of C Programming Language 35
2.1 Basic structure of C program 38
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
Module III
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.
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
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.
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.
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
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
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.
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.
Debugging and maintenance are not Debugging and maintenance are easier in a high-
easier in a low-level language. level language.
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.
Examples C, COBOL, C#, C++, etc Python, VB, Java Script etc.
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.
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.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.