Professional Documents
Culture Documents
EST102 Programming in C
EST102 Programming in C
EST102 Programming in C
PROGRAMMING IN C
MODULE I
SYLLABUS
Basics of Computer Hardware and Software
num1,num2,num3
Output : Average of three numbers
• Identify any other data and
constants required to solve the
problem
The average of numbers is defined
as,
Sum of all inputs
Total number of inputs
Here, other data to be computed is
Sum of all inputs, ie,
Sum = num1 + num2 + num3
• Identify what needs to be computed
The average of three numbers has to
be computed.
Sum
Average =
3
• Write the algorithm
Step 1 : Start
Step 2 : Read three numbers,
num1,num2,num3
Step 3 : Calculate the sum,
Sum = num1 + num2 + num3
Step 4 : Calculate the average,
Average = Sum/3
Step 5 : Print Average
Step 6 : Stop
which can also be written as,
Step 1 : Start
Step 2 : Read num1,num2,num3
Step 3 : Sum = num1 + num2 + num3
Step 4 : Average = Sum/3
Step 5 : Print Average
Step 6 : Stop
Algorithm Flow Chart
Step 1 : Start
Start
Step 2 : Read num1,num2,num3
Step 3 : Sum = num1 + num2 +
num3 Read num1,num2,num3
Print Average
Stop
Question No. 1
Design an algorithm and flow chart to find
area of a circle.
Print Area
Stop
Question No. 2
Write an algorithm and draw flow chart to
find area of a square.
Print Area
Stop
Question No. 3
Write an algorithm and draw the flow chart
to find largest among two numbers.
If
True False
num1> num2
Algorithm
Step 1 : Start
Step 2 : Read num1, num2
Step 3 : If num1 > num2, then, go to Step 4,
otherwise go to Step 5.
Step 4 : Largest = num1 go to Step 6
Step 5 : Largest = num2
Step 6 : Print Largest
Step 7 : Stop
Algorithm
Step 1 : Start
Step 2 : Read num1, num2
Step 3 : If num1 > num2, then, go to Step 4,
otherwise go to Step 5.
Step 4 : Largest = num1 go to Step 6
Step 5 : Largest = num2
Step 6 : Print Largest
Step 7 : Stop
Algorithm
Step 1 : Start
Step 2 : Read num1, num2
Step 3 : If num1 > num2, then, go to Step 4,
otherwise go to Step 5.
Step 4 : Largest = num1 go to Step 6
Step 5 : Largest = num2
Step 6 : Print Largest
Step 7 : Stop
Flow Chart
Start
If
True False
num1> num2
Largest = num1
Algorithm
Step 1 : Start
Step 2 : Read num1, num2
Step 3 : If num1 > num2, then, go to Step 4,
otherwise go to Step 5.
Step 4 : Largest = num1 go to Step 6
Step 5 : Largest = num2
Step 6 : Print Largest
Step 7 : Stop
Algorithm
Step 1 : Start
Step 2 : Read num1, num2
Step 3 : If num1 > num2, then, go to Step 4,
otherwise go to Step 5.
Step 4 : Largest = num1 go to Step 6
Step 5 : Largest = num2
Step 6 : Print Largest
Step 7 : Stop
Algorithm
Step 1 : Start
Step 2 : Read num1, num2
Step 3 : If num1 > num2, then, go to Step 4,
otherwise go to Step 5.
Step 4 : Largest = num1 go to Step 6
Step 5 : Largest = num2
Step 6 : Print Largest
Step 7 : Stop
Flow Chart
Start
If
True False
num1> num2
If
True False
num1> num2
Print
Largest
Algorithm
Step 1 : Start
Step 2 : Read num1, num2
Step 3 : If num1 > num2, then, go to Step 4,
otherwise go to Step 5.
Step 4 : Largest = num1 go to Step 6
Step 5 : Largest = num2
Step 6 : Print Largest
Step 7 : Stop
Flow Chart
Start
If
True False
num1> num2
Print
Largest
Stop
Question No. 4
Write an algorithm and draw the flow chart
to check whether the given number is odd or
even.
Read number, n
Algorithm
Step 1 : Start
Step 2 : Read number, n
Step 3 : Remainder = n % 2
Step 4 : If Remainder == 0, then, go to Step 5,
otherwise go to Step 6.
Step 5 : Print “Even Number” go to Step 7.
Step 6 : Print “Odd Number”
Step 7 : Stop
Flow Chart
Start
Read number, n
Remainder = n % 2
Algorithm
Step 1 : Start
Step 2 : Read number, n
Step 3 : Remainder = n % 2
Step 4 : If Remainder == 0, then, go to Step 5,
otherwise go to Step 6.
Step 5 : Print “Even Number” go to Step 7.
Step 6 : Print “Odd Number”
Step 7 : Stop
Flow Chart
Start
Read number, n
Remainder = n % 2
If
True False
Remainder == 0
Algorithm
Step 1 : Start
Step 2 : Read number, n
Step 3 : Remainder = n % 2
Step 4 : If Remainder == 0, then, go to Step 5,
otherwise go to Step 6.
Step 5 : Print “Even Number” go to Step 7.
Step 6 : Print “Odd Number”
Step 7 : Stop
Algorithm
Step 1 : Start
Step 2 : Read number, n
Step 3 : Remainder = n % 2
Step 4 : If Remainder == 0, then, go to Step 5,
otherwise go to Step 6.
Step 5 : Print “Even Number” go to Step 7.
Step 6 : Print “Odd Number”
Step 7 : Stop
Flow Chart
Start
Read number, n
Remainder = n % 2
If
True False
Remainder == 0
Read number, n
Remainder = n % 2
If
True False
Remainder == 0
Read number, n
Remainder = n % 2
If
True False
Remainder == 0
Stop
Question No. 5
Write an algorithm and draw the flow chart
to print the first n natural numbers where n
is entered by a user.
i=1
Algorithm
Step 1 : Start
Step 2 : Read upper limit, n
Step 3 : Set lower limit, i = 1
Step 4 : Print i
Step 5 : Print “\n”
Step 6 : i = i + 1
Step 7 : Repeat Step 4 to Step 6 until i=n
Step 8 : Stop
Flow Chart
Start
i=1
Print i
Algorithm
Step 1 : Start
Step 2 : Read upper limit, n
Step 3 : Set lower limit, i = 1
Step 4 : Print i
Step 5 : Print “\n”
Step 6 : i = i + 1
Step 7 : Repeat Step 4 to Step 6 until i=n
Step 8 : Stop
Flow Chart
Start
i=1
Print i
Print “\n”
Algorithm
Step 1 : Start
Step 2 : Read upper limit, n
Step 3 : Set lower limit, i = 1
Step 4 : Print i
Step 5 : Print “\n”
Step 6 : i = i + 1
Step 7 : Repeat Step 4 to Step 6 until i=n
Step 8 : Stop
Flow Chart
Start
1)SEQUENCE
2)WHILE
3)REPEAT - UNTIL
4)FOR
5)IF - THEN - ELSE
6)CASE
The main constructs of pseudocode
1)SEQUENCE represents linear task sequentially
performed one after the other.
2)WHILE a loop with a condition at its
beginning.
3)REPEAT - UNTIL a loop with a condition at
the bottom.
4)FOR another way of looping.
5)IF - THEN - ELSE a conditional statement
changing the flow of the algorithm.
6)CASE the generalization form of IF - THEN -
ELSE.
Example
Give the algorithm, draw flow chart and
pseudocode to find the average of three
numbers.
Print Average
Stop
Pseudocode
READ num1,num2,num3
Sum = num1 + num2 + num3
Average = Sum/3
PRINT Average
Question No. 1
Design an algorithm, draw flow chart and
pseudocode to find area of a circle.
Print Area
Stop
Pseudocode
READ r
Area = 3.14 * r * r
PRINT Area
Question No. 2
Write an algorithm, draw flow chart and
pseudocode to find area of a square.
Print Area
Stop
Pseudocode
READ a
Area = a * a
PRINT Area
Question No. 3
Write an algorithm, draw flow chart and
pseudocode to find largest among two
numbers.
If
True False
num1> num2
Print
Largest
Stop
Pseudocode
READ num1, num2
IF num1 > num2
THEN
Largest = num1
ELSE
Largest = num2
ENDIF
PRINT Largest
Question No. 4
Write an algorithm, draw flow chart and
pseudocode to check whether the given
number is odd or even.
Read number, n
Remainder = n % 2
If
True False
Remainder == 0
Stop
Pseudocode
READ n
Remainder = n % 2
IF Remainder == 0
THEN
PRINT “Even Number”
ELSE
PRINT “Odd Number”
ENDIF
Difference b/w Algorithm,Flow Chart and
pseudo Code
Sl. Algorithm Flow Chart Pseudo Code
No.
Element to search : 1
Element is present at location 3.
Write an algorithm to search an element in
an array using linear search.
i=0
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Step 7 : Read element to be searched, k
Flow Chart
Start
i=0
i=0
i=i+1
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Step 7 : Read element to be searched, k
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Step 7 : Read element to be searched, k
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Step 7 : Read element to be searched, k
Flow Chart
Start
i=0
i=i+1
Flow Chart
Read element to
be searched, k
False
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Flow Chart
Read element to
be searched, k
j=0
False
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Flow Chart
Read element to
be searched, k
j=0
Check
True whether
False
j<n
False
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Flow Chart
Read element to
be searched, k
j=0
Check
True whether
False
j<n
False
If
True
a[j]==k
False
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Flow Chart
Read element to
be searched, k
j=0
Check
True whether
False
j<n
False
If
True
a[j]==k
False
Print “Element is
present at position j”
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Flow Chart
Read element to
be searched, k
j=0
Check
True whether
False
j<n
False
If
True
a[j]==k
False
Print “Element is
present at position j” j = j+1
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Flow Chart
Read element to
be searched, k
j=0
Check
True whether
False
j<n
False If
If False
True j==n
a[j]==k
True
False
Print “Element is
present at position j” j = j+1
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Step 14 : Print “Element is not present”
Step 15 : Stop
Flow Chart
Read element to
be searched, k
j=0
Check
True whether
False
j<n
False If
If False
True j==n
a[j]==k
True
False Print “Element
Print “Element is is not present”
present at position j” j = j+1
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Step 14 : Print “Element is not present”
Step 15 : Stop
Flow Chart
Read element to
be searched, k
j=0
Check
True whether
False
j<n
False If
If False
True j==n
a[j]==k
True
False Print “Element
Print “Element is
is not present”
present at position j” j = j+1
Stop
Write the pseudocode to search an element
in an array using linear search.
Pseudocode
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Step 7 : Read element to be searched, k
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Step 7 : Read element to be searched, k
Pseudocode
READ n
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Step 7 : Read element to be searched, k
Pseudocode
READ n
SET i = 0
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Step 7 : Read element to be searched, k
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Step 7 : Read element to be searched, k
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Step 7 : Read element to be searched, k
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
READ k
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
READ k
SET j = 0
Step 8 : Set j = 0
Step 9 : Check whether j < n, if it is true,
then go to Step 10. Otherwise,
go to Step 13.
Step 10 : If a[j] == k, then go to Step 11.
Otherwise, go to Step 12.
Step 11 : Print “Element is present at
position j” go to Step 15
Step 12 : j = j + 1 go to Step 9
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
READ k
SET j = 0
WHILE j < n
IF a[j] == k
THEN
PRINT “Element is present at
position j”
BREAK
ENDIF
j=j+1
ENDWHILE
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Step 14 : Print “Element is not present”
Step 15 : Stop
Step 13 : If j == n, then go to Step 14.
Otherwise, go to Step 15.
Step 14 : Print “Element is not present”
Step 15 : Stop
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
READ k
SET j = 0
WHILE j < n
IF a[j] == k
THEN
PRINT “Element is present at position j”
BREAK
ENDIF
j=j+1
ENDWHILE
IF j == n
THEN
PRINT “Element is not present”
ENDIF
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
READ k
SET j = 0
WHILE j < n
IF a[j] == k
THEN
PRINT “Element is present at position j”
BREAK
ENDIF
j=j+1
ENDWHILE
IF j == n
THEN
PRINT “Element is not present”
ENDIF
Bubble Sort
• Bubble sort, also referred to as
Comparison sort, is a simple sorting
algorithm.
• It repeatedly goes through the list,
compares adjacent elements and swaps
them if they are in the wrong order.
• Bubble sort is the easiest sorting
algorithm to implement.
• It is an in-place sorting algorithm.
In real life, bubble sort can be
visualised when people in a queue
wanting to be standing in a height wise
sorted manner swap their positions
among themselves until everyone is
standing based on increasing order of
heights.
How Bubble Sort works?
• Bubble sort uses multiple passes (scans)
through an array.
• In each pass, bubble sort compares the
adjacent elements of the array.
• It then swaps the two elements if they are
in the wrong order.
• In each pass, bubble sort places the next
largest element to its proper position.
• In short, it bubbles down the largest
element to its correct position.
Example
Index 0 1 2 3 4
A 14 33 27 35 10
Value A[0] A[1] A[2] A[3] A[4]
We need to sort this array in ascending order
using bubble sort.
Expected Output:
Index 0 1 2 3 4
A 10 14 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
Input :
Index 0 1 2 3 4
A 14 33 27 35 10
Value A[0] A[1] A[2] A[3] A[4]
First Pass
We proceed with the first and second element.
ie, A[0] and A[1].
Check if A[0] > A[1]
=> 14 > 33
=> FALSE
So, no swapping happens and the array
remains the same.
Index 0 1 2 3 4
A 14 33 27 35 10
Value A[0] A[1] A[2] A[3] A[4]
We proceed with the second and third element.
ie, A[1] and A[2].
Check if A[1] > A[2]
=> 33 > 27
=> TRUE
So, we swap A[1] and A[2].
Index 0 1 2 3 4
A 14 33 27 35 10
Value A[0] A[1] A[2] A[3] A[4]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 33 27 35 10
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 33 27 35 10
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 33
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 33 27 35 10
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 33 A[1] = A[2]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 33 27 27 35 10
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 33 A[1] = A[2]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 27 35 10
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 33 A[1] = A[2]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 27 35 10
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 33 A[1] = A[2]
A[2] = temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 27 33 35 10
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 33 A[1] = A[2]
A[2] = temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 33 35 10
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 33 A[1] = A[2]
A[2] = temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 33 35 10
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 33 A[1] = A[2]
A[2] = temp
Thus the array becomes:
Index 0 1 2 3 4
A 14 27 33 35 10
Value A[0] A[1] A[2] A[3] A[4]
We proceed with the third and fourth element.
ie, A[2] and A[3].
Check if A[2] > A[3]
=> 33 > 35
=> FALSE
So, no swapping happens and the array
remains the same.
Index 0 1 2 3 4
A 14 27 33 35 10
Value A[0] A[1] A[2] A[3] A[4]
We proceed with the fourth and fifth element.
ie, A[3] and A[4].
Check if A[3] > A[4]
=> 35 > 10
=> TRUE
So, we swap A[3] and A[4].
Index 0 1 2 3 4
A 14 27 33 35 10
Value A[0] A[1] A[2] A[3] A[4]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 33 35 10
Value A[0] A[1] A[2] A[3] A[4]
temp = A[3]
temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 33 35 10
Value A[0] A[1] A[2] A[3] A[4]
temp = A[3]
temp 35
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 33 35 10
Value A[0] A[1] A[2] A[3] A[4]
temp = A[3]
temp 35 A[3] = A[4]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 33 35 10 10
Value A[0] A[1] A[2] A[3] A[4]
temp = A[3]
temp 35 A[3] = A[4]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 33 10 10
Value A[0] A[1] A[2] A[3] A[4]
temp = A[3]
temp 35 A[3] = A[4]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 33 10 10
Value A[0] A[1] A[2] A[3] A[4]
temp = A[3]
temp 35 A[3] = A[4]
A[4] = temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 33 10 10 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[3]
temp 35 A[3] = A[4]
A[4] = temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 33 10 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[3]
temp 35 A[3] = A[4]
A[4] = temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 33 10 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[3]
temp 35 A[3] = A[4]
A[4] = temp
Thus the array becomes:
Index 0 1 2 3 4
A 14 27 33 10 35
Value A[0] A[1] A[2] A[3] A[4]
Index 0 1 2 3 4
A 14 27 33 10 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[2]
temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 33 10 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[2]
temp 33
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 33 10 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[2]
temp 33 A[2] = A[3]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 33 10 10 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[2]
temp 33 A[2] = A[3]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 10 10 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[2]
temp 33 A[2] = A[3]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 10 10 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[2]
temp 33 A[2] = A[3]
A[3] = temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 10 10 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[2]
temp 33 A[2] = A[3]
A[3] = temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 10 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[2]
temp 33 A[2] = A[3]
A[3] = temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 10 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[2]
temp 33 A[2] = A[3]
A[3] = temp
Thus the array becomes:
Index 0 1 2 3 4
A 14 27 10 33 35
Value A[0] A[1] A[2] A[3] A[4]
Index 0 1 2 3 4
A 14 27 10 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 10 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 27
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 10 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 27 A[1] = A[2]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 27 10 10 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 27 A[1] = A[2]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 10 10 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 27 A[1] = A[2]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 10 10 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 27 A[1] = A[2]
A[2] = temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 10 10 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 27 A[1] = A[2]
A[2] = temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 10 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 27 A[1] = A[2]
A[2] = temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 10 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[1]
temp 27 A[1] = A[2]
A[2] = temp
Thus the array becomes:
Index 0 1 2 3 4
A 14 10 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
Index 0 1 2 3 4
A 14 10 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[0]
temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 10 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[0]
temp 14
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 10 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[0]
temp 14 A[0] = A[1]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 14 10 10 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[0]
temp 14 A[0] = A[1]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 10 10 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[0]
temp 14 A[0] = A[1]
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 10 10 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[0]
temp 14 A[0] = A[1]
A[1] = temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 10 10 14 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[0]
temp 14 A[0] = A[1]
A[1] = temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 10 14 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[0]
temp 14 A[0] = A[1]
A[1] = temp
Swapping will be done with the help of a
third variable.
Index 0 1 2 3 4
A 10 14 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
temp = A[0]
temp 14 A[0] = A[1]
A[1] = temp
Thus the array becomes:
Index 0 1 2 3 4
A 10 14 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
Index 0 1 2 3 4
A 10 14 27 33 35
Value A[0] A[1] A[2] A[3] A[4]
i=0
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Flow Chart
Start
i=0
i=0
i=i+1
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Flow Chart
Start
i=0
i=i+1
j=1
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Flow Chart
Start
i=0
i=i+1
j=1
i=0
i=i+1
j=1
i=0
i=i+1
j=1
i=0
i=i+1
j=1
True Check whether False
j<n
k=0
Check whether False
k<n-j
True
If
a[k] > a[k + 1]
True
False
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Step 12 : temp = a[k]
Step 13 : a[k] = a[k + 1]
Step 14 : a[k + 1] = temp
Step 15 : k = k + 1 go to Step 10.
Step 16 : j = j + 1 go to Step 8.
Step 17 : Set l = 0
Step 18 : Check whether l < n, if it is true,
then go to Step 19. Otherwise, go to
Step 21.
Step 19 : Print a[l]
Step 20 : l = l + 1 go to Step 18.
Step 21 : Stop
Step 12 : temp = a[k]
Step 13 : a[k] = a[k + 1]
Step 14 : a[k + 1] = temp
Step 15 : k = k + 1 go to Step 10.
Step 16 : j = j + 1 go to Step 8.
Step 17 : Set l = 0
Step 18 : Check whether l < n, if it is true,
then go to Step 19. Otherwise, go to
Step 21.
Step 19 : Print a[l]
Step 20 : l = l + 1 go to Step 18.
Step 21 : Stop
Flow Chart
Start
i=0
i=i+1
j=1
True Check whether False
j<n
k=0
Check whether False
k<n-j
True
If
a[k] > a[k + 1]
True
i=0
i=i+1
j=1
True Check whether False
j<n
k=0
Check whether False
k<n-j
True
If
a[k] > a[k + 1]
True
i=0
i=i+1
j=1
True Check whether False
j<n
k=0
Check whether False
k<n-j
True
If
a[k] > a[k + 1]
True
i=0
i=i+1
j=1
True Check whether False
j<n
k=0
Check whether False
k<n-j
True j=j+1
If
a[k] > a[k + 1]
True
i=0
i=i+1
j=1
True Check whether False
j<n
k=0 l=0
Check whether False
k<n-j
True j=j+1
If
a[k] > a[k + 1]
True
i=0
i=i+1
j=1
True Check whether False
j<n
k=0 l=0
Check whether False False Check whether
k<n-j l<n
True j=j+1
True
If
a[k] > a[k + 1]
True
i=0
i=i+1
j=1
True Check whether False
j<n
k=0 l=0
Check whether False False Check whether
k<n-j l<n
True j=j+1
True
If
a[k] > a[k + 1]
True
Print a[l]
False temp = a[k]
k=k+1 a[k] = a[k+1] l=l+1
a[k+1] = temp
Step 12 : temp = a[k]
Step 13 : a[k] = a[k + 1]
Step 14 : a[k + 1] = temp
Step 15 : k = k + 1 go to Step 10.
Step 16 : j = j + 1 go to Step 8.
Step 17 : Set l = 0
Step 18 : Check whether l < n, if it is true,
then go to Step 19. Otherwise, go to
Step 21.
Step 19 : Print a[l]
Step 20 : l = l + 1 go to Step 18.
Step 21 : Stop
Step 12 : temp = a[k]
Step 13 : a[k] = a[k + 1]
Step 14 : a[k + 1] = temp
Step 15 : k = k + 1 go to Step 10.
Step 16 : j = j + 1 go to Step 8.
Step 17 : Set l = 0
Step 18 : Check whether l < n, if it is true,
then go to Step 19. Otherwise, go to
Step 21.
Step 19 : Print a[l]
Step 20 : l = l + 1 go to Step 18.
Step 21 : Stop
Step 12 : temp = a[k]
Step 13 : a[k] = a[k + 1]
Step 14 : a[k + 1] = temp
Step 15 : k = k + 1 go to Step 10.
Step 16 : j = j + 1 go to Step 8.
Step 17 : Set l = 0
Step 18 : Check whether l < n, if it is true,
then go to Step 19. Otherwise, go to
Step 21.
Step 19 : Print a[l]
Step 20 : l = l + 1 go to Step 18.
Step 21 : Stop
Flow Chart
Start
i=0
i=i+1
j=1
True Check whether False
j<n
k=0 l=0
Check whether False False Check whether
k<n-j l<n
True j=j+1
True
If
a[k] > a[k + 1]
True
Print a[l]
False temp = a[k]
k=k+1 a[k] = a[k+1] l=l+1
a[k+1] = temp
Stop
Write the pseudocode to sort an array in
ascending order using bubble sort.
Pseudocode
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Step 12 : temp = a[k]
Step 13 : a[k] = a[k + 1]
Step 14 : a[k + 1] = temp
Step 15 : k = k + 1 go to Step 10.
Step 16 : j = j + 1 go to Step 8.
Step 17 : Set l = 0
Step 18 : Check whether l < n, if it is true,
then go to Step 19. Otherwise, go to
Step 21.
Step 19 : Print a[l]
Step 20 : l = l + 1 go to Step 18.
Step 21 : Stop
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Pseudocode
READ n
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Pseudocode
READ n
SET i = 0
Algorithm
Step 1 : Start
Step 2 : Read size of the array, n
Step 3 : Set, i = 0
Step 4 : Check whether i < n, if it is true,
then go to Step 5. Otherwise, go
to Step 7.
Step 5 : Read a[i]
Step 6 : i = i + 1 go to Step 4
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
SET j = 1
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
SET j = 1
WHILE j < n
ENDWHILE
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
SET j = 1
WHILE j < n
SET k = 0
ENDWHILE
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
SET j = 1
WHILE j < n
SET k = 0
WHILE k < n - j
ENDWHILE
ENDWHILE
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
SET j = 1
WHILE j < n
SET k = 0
WHILE k < n - j
IF a[k] > a[k + 1]
THEN
ENDIF
ENDWHILE
ENDWHILE
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Step 12 : temp = a[k]
Step 13 : a[k] = a[k + 1]
Step 14 : a[k + 1] = temp
Step 15 : k = k + 1 go to Step 10.
Step 16 : j = j + 1 go to Step 8.
Step 17 : Set l = 0
Step 18 : Check whether l < n, if it is true,
then go to Step 19. Otherwise, go to
Step 21.
Step 19 : Print a[l]
Step 20 : l = l + 1 go to Step 18.
Step 21 : Stop
Step 12 : temp = a[k]
Step 13 : a[k] = a[k + 1]
Step 14 : a[k + 1] = temp
Step 15 : k = k + 1 go to Step 10.
Step 16 : j = j + 1 go to Step 8.
Step 17 : Set l = 0
Step 18 : Check whether l < n, if it is true,
then go to Step 19. Otherwise, go to
Step 21.
Step 19 : Print a[l]
Step 20 : l = l + 1 go to Step 18.
Step 21 : Stop
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
SET j = 1
WHILE j < n
SET k = 0
WHILE k < n - j
IF a[k] > a[k + 1]
THEN
temp = a[k]
a[k] = a[k + 1]
a[k + 1] = temp
ENDIF
ENDWHILE
ENDWHILE
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Step 12 : temp = a[k]
Step 13 : a[k] = a[k + 1]
Step 14 : a[k + 1] = temp
Step 15 : k = k + 1 go to Step 10.
Step 16 : j = j + 1 go to Step 8.
Step 17 : Set l = 0
Step 18 : Check whether l < n, if it is true,
then go to Step 19. Otherwise, go to
Step 21.
Step 19 : Print a[l]
Step 20 : l = l + 1 go to Step 18.
Step 21 : Stop
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
SET j = 1
WHILE j < n
SET k = 0
WHILE k < n - j
IF a[k] > a[k + 1]
THEN
temp = a[k]
a[k] = a[k + 1]
a[k + 1] = temp
ENDIF
ENDWHILE
ENDWHILE
WHILE j < n
SET k = 0
WHILE k < n - j
IF a[k] > a[k + 1]
THEN
temp = a[k]
a[k] = a[k + 1]
a[k + 1] = temp
ENDIF
k=k+1
ENDWHILE
ENDWHILE
Step 7 : Set j = 1
Step 8 : Check whether j < n, if it is true,
then go to Step 9. Otherwise, go
to Step 17.
Step 9 : Set k = 0
Step 10 : Check whether k < n - j, if it is
true, then go to Step 11.
Otherwise, go to Step 16.
Step 11 : If a[k] > a[k + 1], then go to
Step 12. Otherwise, go to Step
15.
Step 12 : temp = a[k]
Step 13 : a[k] = a[k + 1]
Step 14 : a[k + 1] = temp
Step 15 : k = k + 1 go to Step 10.
Step 16 : j = j + 1 go to Step 8.
Step 17 : Set l = 0
Step 18 : Check whether l < n, if it is true,
then go to Step 19. Otherwise, go to
Step 21.
Step 19 : Print a[l]
Step 20 : l = l + 1 go to Step 18.
Step 21 : Stop
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
SET j = 1
WHILE j < n
SET k = 0
WHILE k < n - j
IF a[k] > a[k + 1]
THEN
temp = a[k]
a[k] = a[k + 1]
a[k + 1] = temp
ENDIF
k=k+1
ENDWHILE
ENDWHILE
WHILE j < n
SET k = 0
WHILE k < n - j
IF a[k] > a[k + 1]
THEN
temp = a[k]
a[k] = a[k + 1]
a[k + 1] = temp
ENDIF
k=k+1
ENDWHILE
j=j+1
ENDWHILE
Step 12 : temp = a[k]
Step 13 : a[k] = a[k + 1]
Step 14 : a[k + 1] = temp
Step 15 : k = k + 1 go to Step 10.
Step 16 : j = j + 1 go to Step 8.
Step 17 : Set l = 0
Step 18 : Check whether l < n, if it is true,
then go to Step 19. Otherwise, go to
Step 21.
Step 19 : Print a[l]
Step 20 : l = l + 1 go to Step 18.
Step 21 : Stop
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
SET j = 1
WHILE j < n
SET k = 0
WHILE k < n - j
IF a[k] > a[k + 1]
THEN
temp = a[k]
a[k] = a[k + 1]
a[k + 1] = temp
ENDIF
k=k+1
ENDWHILE
j=j+1
ENDWHILE
SET l = 0
Step 12 : temp = a[k]
Step 13 : a[k] = a[k + 1]
Step 14 : a[k + 1] = temp
Step 15 : k = k + 1 go to Step 10.
Step 16 : j = j + 1 go to Step 8.
Step 17 : Set l = 0
Step 18 : Check whether l < n, if it is true,
then go to Step 19. Otherwise, go to
Step 21.
Step 19 : Print a[l]
Step 20 : l = l + 1 go to Step 18.
Step 21 : Stop
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
SET j = 1
WHILE j < n
SET k = 0
WHILE k < n - j
IF a[k] > a[k + 1]
THEN
temp = a[k]
a[k] = a[k + 1]
a[k + 1] = temp
ENDIF
k=k+1
ENDWHILE
j=j+1
ENDWHILE
SET l = 0
WHILE l < n
PRINT a[l]
l=l+1
ENDWHILE
Pseudocode
READ n
SET i = 0
WHILE i < n
READ a[i]
i=i+1
ENDWHILE
SET j = 1
WHILE j < n
SET k = 0
WHILE k < n - j
IF a[k] > a[k + 1]
THEN
temp = a[k]
a[k] = a[k + 1]
a[k + 1] = temp
ENDIF
k=k+1
ENDWHILE
j=j+1
ENDWHILE
SET l = 0
WHILE l < n
PRINT a[l]
l=l+1
ENDWHILE
Thank you…….