You are on page 1of 3

4.

SORTING CHARACTERS IN THE GIVEN ARRAY

July 1, 2014

Aim:
~~~
To write a program using sorting characters in given array using .net.
Procedure:
~~~~~~~~
Step1: Start the program in the Microsoft Visual Studio 2010.
Step2: File->new->project Select the project type as visual basic and select
the visual studio installed template as console application.
Step3: Choose a Name, Location and Solution name.
Step4: Declare the variables.
Step5: Get the Input String in array variable and assign k variable.
Step6: Using for Each loop to assign str=s and increment a k values as 1.
Step7: Using for loop i and j to check the conditions as str(i)>str(j) and swap the
variables
Step8: End of the program.

12PA01

Page 10

4. SORTING CHARACTERS IN THE GIVEN ARRAY

July 1, 2014

Coding:
~~~~~
Module Module1
Sub Main()
Dim str(10), t As Char
Dim s As String
Dim i, j, k As Integer
Console.WriteLine("Sorting Characters is given Array")
Console.WriteLine("***************************")
Console.WriteLine("Input")
Console.WriteLine("------")
Console.WriteLine("Enter the string :")
s = Console.ReadLine ()
For Each element In s
str = s
k=k+1
Next
Console.WriteLine("Output")
Console.WriteLine("--------")
For i = 0 To k - 1
For j = 0 To k - 1
If (str(i) < str(j)) Then
t = str(i)
str(i) = str(j)
str(j) = t
End If
Next j
Next i
Console.WriteLine("Sorting string is:")
For i = 0 To k - 1
Console.WriteLine(str(i))
Next i
Console.ReadKey()
End Sub
End Module
12PA01

Page 11

4. SORTING CHARACTERS IN THE GIVEN ARRAY

July 1, 2014

Output
~~~~~~
Sorting Characters is given Array
***************************
Input
-----Enter the string :
welcome
Output
-------Sorting string is:
c
e
e
l
m
o
w

Result:
*****
Thus the sorting characters in an given array program was successfully performed.

12PA01

Page 12

You might also like