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
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Selva GanapathyPosted Feb 25, 2014, 11:03 PM
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
Selva GanapathyPosted Feb 26, 2014, 12:19 AM
Welcome :)
Regards,
Selva Ganapathy K
Guest UserPosted Feb 25, 2014, 11:12 PM