对n个整数组成的一维数组按逆序重新存储并输出(n<10)
int[] arr = new int[9];
int i,j,n,temp;
//读入一个整数n
Console.WriteLine("请输入n!");
try
{
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入需要逆序的数组!");
for (i = 0; i < n; i++)//输入数组
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
for (i = 0, j = n - 1; i < j; i++, j--)
{//交换位置
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
Console.WriteLine("逆序之后的数组为");
for (i = 0; i < n; i++)
{
Console.Write(arr[i] + " ");
}
}
catch (Exception)
{
Console.Write("错误!!!n必须小于10!");
throw;
}