作业三

要求


程序

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            try

            {

                Console.WriteLine("请输入4家店的价格");

                int[] jg =new int [4];


                for(int i = 0;i<jg.Length;i++)

              {

                    Console.WriteLine("请输入第{0}家店的价格:", i + 1);

                    jg[i] = Convert.ToInt32(Console.ReadLine());

                }

                for (int i = 0; i < jg.Length - 1; i++)

                {

                    for (int j = 0; j < jg.Length - 1 - i; j++)

                    {

                        if (jg[j] > jg[j + 1])

                        {

                            int temp = jg[j];

                            jg[j] = jg[j + 1];

                            jg[j + 1] = temp;

                        }

                    }

                }

                Console.WriteLine("");

                Console.WriteLine("最低价格是:{0}", jg[0]);         

            }

            catch

            {

                Console.WriteLine("你的格式输入有误");

            }

            Console.ReadKey();

        }

    }

效果




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

推荐阅读更多精彩内容