Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Sort Numbers in Ascending Order using C#
WhatsApp
Vijayaragavan S
Aug 09
2016
100.7
k
0
0
using
System;
class
Program
{
static
void
Main()
{
int
i;
int
[] a =
new
int
[30];
// Array Declaration in C#
Console.Write(
"Enter the Number of values to be Sort : "
);
// read the string value (by default) and convert it in to integer
int
n = Convert.ToInt16(Console.ReadLine());
//Reading the values one by one
for
(i = 1; i <= n; i++)
{
Console.Write(
"Enter the No "
+ i +
":"
);
// read the string value (by default) and convert it in to integer
a[i] = Convert.ToInt16(Console.ReadLine());
}
//Sorting the values
for
(i = 1; i <= n; i++)
{
for
(
int
j = 1; j <= n - 1; j++)
{
if
(a[j] > a[j + 1])
{
int
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
//Display the Ascending values one by one
Console.Write(
"Ascending Sort : "
);
for
(i = 1; i <= n; i++)
{
Console.Write(a[i]+
" "
);
}
//Waiting for output
Console.ReadKey();
}
}
Ascending
Arrays
C#
for Loop
Up Next
Sort Numbers in Ascending Order using C#