标签:i++ read 排序 line ons length lin 输入 数组
Console.Write("请输入数组的长度:");
int n=int.Parse(Console.ReadLine());
int[] nums=new int[n];
for (int i = 0; i < nums.Length; i++) {
Console.Write("请输入第"+(i+1)+"个数");
nums[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine();
Console.WriteLine("你输入的数字排序后的顺序:");
for (int i = 0; i < nums.Length-1; i++)
{
for (int j = i + 1; j < nums.Length; j++) {
if (nums[i] > nums[j]) {
int t = nums[i];
nums[i] = nums[j];
nums[j] = t;
}
}
}
for (int j = 0; j < nums.Length; j++)
{
Console.Write(nums[j] + " ");
}
Console.WriteLine();
Console.WriteLine("其中奇数是:");
for (int j = 0; j < nums.Length; j++)
{
if (nums[j] % 2 == 1) {
Console.Write(nums[j] + " ");
}
}
Console.WriteLine();
Console.WriteLine("其中质数是:");
for (int i = 0; i < nums.Length; i++)
{
int m = 0;
for (int j = 1; j <= nums[i]; j++)
{
if (nums[i] % j == 0)
{
m++;
}
}
if (m == 2)
{
Console.Write(nums[i]+" ");
}
}
标签:i++ read 排序 line ons length lin 输入 数组
原文地址:http://www.cnblogs.com/AndHowAreYou/p/7581987.html