Well the title of your question says that you want to sort the vector. But the posted code prints the pairs and adds the odd ones. Here is an answer to what was asked, ordering a vector of int . If you want to only place the odd ones in ascending order, follow the logic of separating them and placing them in a list then use this Array.Sort(numeros);
to sort.
int[] numeros = { 10, 5, 20, 60, 1, 5, 8, 30, 11, 20, 25, 30, 50 };
Console.Write("Números ordenados");
Array.Sort(numeros);
// Escrevendo array
foreach (int i in numeros) Console.Write(i + " ");
Following your code , just to sort the odd ones would look like this:
int c = 0;
List numeros = new List(){ 10, 5, 20, 60, 1, 5, 8, 30, 11, 20, 25, 30, 50 };
List impares = new List();
Console.Write("Números pares");
foreach (int num in numeros)
{
if (num % 2 == 0)
{
Console.Write(num + ", ");
}
else
{
impares.Add(num);
}
}
Array.Sort(impares);
Console.WriteLine("\n numeros impares ordenados");
foreach (int ordImp in impares)
{
System.Console.WriteLine(ordImp);
}
Console.ReadKey();