2018-12-19

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();

        }

    }

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 2,736评论 0 3
  • using System; using System.Collections.Generic; using Sys...
    一只皮皮橙阅读 197评论 0 0
  • 训练1: 某百货商场当日消费积分最高的8名顾客,他们的积分分别是18、25、7、36、13、2、89、63.编写程...
    be1058558528阅读 522评论 0 0
  • 【今日话题】你认为自己能够为大家提供的价值有哪些? 1.提供傾聽的能力, 認真的傾聽, 清楚的回應 2.正能量, ...
    妹酱让今天比昨天更好阅读 118评论 0 0
  • 使用@property声明属性时,经常用到atomic与nonatomic两个关键字,默认为atomic。atom...
    兰帕德阅读 490评论 0 0