static void Main(string[] args)
{
#region 创建数组
Console.Write("请输入数组的长度");
int[] numbers = new int[int.Parse(Console.ReadLine())];
for (int i = 0; i < numbers.Length; i++)
{
Console.Write("请输入数组的第" + (i + 1) + "项:");
numbers[i] = int.Parse(Console.ReadLine());
}
Console.Clear();
#endregion
#region 对组数排序
for (int i = 0; i < numbers.Length-1; i++)
{
for (int j = i+1; j < numbers.Length; j++)
{
if (numbers[i] > numbers[j])
{
int temp = numbers[i];
numbers[i] = numbers[j];
numbers[j] = temp;
}
}
}
Console.WriteLine("您输入的数字排序后如下:");
for (int i = 0; i < numbers.Length; i++)
{
Console.Write(numbers[i]+"\t");
}
Console.WriteLine();
#endregion
#region 找出奇数
Console.WriteLine("其中,以下数字是奇数:");
//查找问题
//查找样本:数组中所有的数字
//查找目标:样本数据除以2不为0
//找到后的操作:输出目标数据
for (int i = 0; i < numbers.Length; i++)
{
int n = numbers[i];
if (n % 2 != 0)
{
Console.Write(n + "\t");
}
}
Console.WriteLine();
#endregion
#region 找出质数
Console.WriteLine("以下数字式质数:");
for (int i = 0; i < numbers.Length; i++)
{
int n = numbers[i];
bool isfind = false;
for (int j = 2; j < n; j++)
{
if (n % j == 0)
{
isfind = true;
break;
}
}
if(!isfind)
{
{
Console.Write(n+"\t");
}
}
}
#endregion
}
转载于:https://www.cnblogs.com/Maigo/p/8638606.html