Reverse elements in an array

后端 未结 6 1890
既然无缘
既然无缘 2020-11-30 14:58

I setup an array and i would like to create a method that will return an array with the elements in reverse. e.g. if there are 10 slots then array1[9] = 6 so

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 15:51

           int a;
            Console.WriteLine("Enter the array length");
            a=int.Parse(Console.ReadLine());
            Console.WriteLine("enter the array element");
            int[] sau = new int[a];
            for (int i = 0; i < a; i++)
            {
                sau[i] = int.Parse(Console.ReadLine());
            }
            for (int i =a.Length-1 ; i < 0;i--)
            {
                Console.WriteLine(sau[i]);
            }
                Console.ReadLine();
        }
    }
    

    }

提交回复
热议问题