number sort using c#.net

Posted by Naga116 under C# on 7/23/2011 | Points: 10 | Views : 36239 | Status : [Member] | Replies : 3
Sort an array without using any method
asked question like 4,1,9,7 Sort.
Please provide the answer

Nagaraju


Responses

Posted by: A4u_6178 on: 7/23/2011 [Member] Starter | Points: 25

Up
0
Down
hi,
I hope this will help...
http://en.literateprograms.org/Bubble_sort_(C_Sharp)

Thanks & Regards,

Naga116, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: RaviRanjanKr on: 7/23/2011 [Member] Starter | Points: 25

Up
0
Down
I will always recommend you to use Array.Sort() function to short array element whatever you can use given code to short data in efficient way
int[] arr = { 4, 1, 9, 7 };

arr = (from a in arr orderby a ascending select a).ToArray();

foreach (int i in arr)
{
Console.WriteLine(i);
}


Output :-
1
4
7
9


Thanks
Ravi Ranjan Kumar
http://raviranjankr.wordpress.com

Naga116, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Graha on: 7/25/2011 [Member] Starter | Points: 25

Up
0
Down
Sorting Program using C#

In this program, just sort the numbers without using any methods.....

To open the Console application and write the code
namespace SortingNos
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Numbers :");
int[] arr = new int[5];
string arr1 = "";
for (int i = 0; i < 5; i++)
{
arr1 = Console.ReadLine();
arr[i] = Convert.ToInt32(arr1);
}

int a, b, temp = 0;
Console.WriteLine();
for (a = 0; a < arr.Length; a++)
{
for(b=a+1;b< arr.Length;b++)
{
if (arr[a] > arr[b])
{
temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
}
Console.WriteLine(arr[a]);
}
Console.ReadLine();
}
}
}



run the program....The sample output is

Enter Numbers :
50
23
10
4
7

Below are The sorted numbers
4
7
10
23
50



Naga116, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response