0% found this document useful (0 votes)
10 views

Sorting Characters in The Given Array July 1, 2014

This document describes a program to sort characters in a given array using Visual Basic. The program prompts the user to input a string, stores each character in an array, then uses nested for loops to compare and swap characters so that the characters are in alphabetical order. The output displays the sorted characters. The aim of the program was achieved by writing code to accept input, store it in an array, sort the characters using loops, and display the output, successfully performing the character sorting.

Uploaded by

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

Sorting Characters in The Given Array July 1, 2014

This document describes a program to sort characters in a given array using Visual Basic. The program prompts the user to input a string, stores each character in an array, then uses nested for loops to compare and swap characters so that the characters are in alphabetical order. The output displays the sorted characters. The aim of the program was achieved by writing code to accept input, store it in an array, sort the characters using loops, and display the output, successfully performing the character sorting.

Uploaded by

Amutha Arun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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