using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
try
{
int[] array = { 1, 3, -1, 5, -2 };
int[] newarray = new int[array.Length];
int k = -1;
for (int i = array.Length - 1; i >= 0; i--)
{
k++;
if (array[i] > 0)
{
newarray[k] = array[i];
}
else
{
newarray[k] = 0;
}
}
Console.WriteLine("原数组为:");
foreach(var item in array)
{
Console.Write(item + "\t");
}
Console.WriteLine("\t");
Console.WriteLine("逆序并处理后的数组为:");
foreach (var item in newarray)
{
Console.Write(item + "\t");
}
}
catch
{
Console.WriteLine("您输入的程序错误");
}
Console.ReadKey();
}
}
}
网友评论