用c#编写一个程序 将一个数组逆序输出

2024-11-20 22:25:18
推荐回答(2个)
回答1:

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication1
{
 
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };

            Console.WriteLine("顺序输出");
            for (int i = 0; i < a.Length; i++)
            {
                Console.Write("{0} ", a[i]);
            }
            
            Console.WriteLine();
            
            Console.WriteLine("逆序输出");
            for (int i = a.Length - 1; i >= 0; i--)
            {
                Console.Write("{0} ", a[i]);
            }
        }
    }
}

回答2:

123456789101112131415161718192021222324252627282930using System;using System.Text;using System.Collections.Generic;using System.Linq; namespace ConsoleApplication1{ class Program { static void Main(string[] args) { int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; Console.WriteLine("顺序输出"); for (int i = 0; i < a.Length; i++) { Console.Write("{0} ", a[i]); } Console.WriteLine(); Console.WriteLine("逆序输出"); for (int i = a.Length - 1; i >= 0; i--) { Console.Write("{0} ", a[i]); } } }}