image.png
int[] a = new int[20];
Random b = new Random();
for (int c = 0; c < a.Length; c++)
{
a[c] = b.Next(1, 101);
}
int count = 0;
for (int c = 0; c < a.Length; c++)//奇数
{
if (a[c] % 2 == 1)
{
int temp = a[count];
a[count] = a[c];
a[c] = temp;
count++;
}
}
for (int c = 0; c < count - 1; c++)//偶数
{
for (int j = 0; j < count - 1; j++)
{
if (a[j] > a[j + 1])
{
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
for (int c = count - 1; c < a.Length - 1; c++)//从小到大排序
{
for (int j = count; j < a.Length - 1; j++)
{
if (a[j] > a[j + 1])
{
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
foreach (var item in a)
{
Console.WriteLine(item);
}
网友评论