Hii all
Have an other question about console application
Here is the question...Thanks
Write an algorithm that ask
user to enter values
within an array of 12
positions. Then, it should be
the values shown in order
ascending and descending.
OUTPUT
The vector in the position [0] = 4
The vector in the position [1] = 1
The vector in the position [2] = 5
The vector in the position [3] = 2
The vector in the position [4] = 3
The vector in the position [5] = 6
The vector in the position [6] = 7
The vector in the position [7] = 9
The vector in the position [8] = 8
The vector in the position [9] = 11
The vector in the position [10] = 0
The vector in the position [11] = 10
Ascending
0
1
2
3
4
5
6
7
8
9
10
11
Descending
11
10
9
8
7
6
5
4
3
2
1
0

Selva GanapathyRank #560 · 4.3K reputationPosted Feb 25, 2014, 6:03 PM EST
The following code C# code snippet is a way to meet your question.
namespace sorting
{
class Program
{
static void Main(string[] args)
{
int[] array = new int[12];
for (int i = 0; i < 12; i++)
{
var n = 0;
Console.Write("Enter Vector in the position [" +i.ToString() + "] = ");
array[i] = Convert.ToInt16(Console.ReadLine());
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Entered values");
Console.WriteLine();
foreach(var i in array)
{
var n = 0;
Console.WriteLine("The Vector in the position [" + (n++).ToString() + "] = " + i.ToString ());
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Ascending");
Console.WriteLine();
Array.Sort(array);
foreach (var i in array)
{
Console.WriteLine(i.ToString());
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Descending");
Console.WriteLine();
Array.Reverse(array);
foreach (var i in array)
{
Console.WriteLine(i.ToString());
}
Console.ReadLine();
}
}
}
Regards,
Selva Ganapathy K
Guest User28 reputationPosted Feb 25, 2014, 6:12 PM EST
Selva GanapathyRank #560 · 4.3K reputationPosted Feb 25, 2014, 7:19 PM EST
Welcome :)
Regards,
Selva Ganapathy K