C # output all elements in an array in reverse order

Source: Internet
Author: User

Step 1: Create a C # console Project

Step 2: Compile the corresponding encoding implementation as follows:

Class Program
{
Static void main (string [] ARGs)
{
Int [] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Reverse (array );
Console. Read ();
}

Static void reverse (INT [] array)
{
For (INT I = 0; I <array. length; I ++)
{
Console. Write (array [I]. tostring () + ",");
}
Console. writeline ();
Int temp;
For (Int J = 0; j <array. Length/2; j ++)
{
Temp = array [J];
Array [J] = array [array. Length-J-1];
Array [array. Length-J-1] = temp;
}
For (int K = 0; k <array. length; k ++)
{
Console. Write (array [K]. tostring () + ",");
}
}
}

Conclusion: although such a simple algorithm is difficult for many new interviewers, they are used to copying and pasting others' code on the Internet, but gradually forget to think about the problem by themselves, although the ability to solve problems means that imitating others is a great creation, or a great copy of the article in the world, you will not copy it. One thing we must remember is to learn to think.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.