寰幆璇彞

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了寰幆璇彞相关的知识,希望对你有一定的参考价值。

鏍囩锛?/p>

for

鏍煎紡锛?/p>

  for (int i = 1/*鍒濆鏉′欢*/; i <= 100/* 寰幆鏉′欢*/; i++ /*鐘舵€佹敼鍙?/)

  {

  //寰幆浣擄紝鎵ц浠g爜锛?break;璺冲嚭寰幆浣?

  }

缁欏嚭鍒濆鏉′欢锛屽厛鍒ゆ柇鏄惁婊¤冻寰幆鏉′欢锛屽鏋滀笉婊¤冻鏉′欢鍒欒烦杩噁or璇彞锛屽鏋滄弧瓒冲垯杩涘叆for璇彞鎵ц锛宖or璇彞鍐呯殑浠g爜鎵ц瀹屾瘯鍚庯紝灏嗘寜鐓х姸鎬佹敼鍙橈紝鏀瑰彉鍙橀噺锛岀劧鍚庡垽鏂槸鍚︾鍚堝惊鐜潯浠讹紝绗﹀悎鍒欑户缁墽琛宖or璇彞鍐呯殑浠g爜锛岀洿鍒板彉閲廼涓嶇鍚堝惊鐜潯浠跺垯缁堟寰幆锛屾垨鑰呯鍒癰reak;鍛戒护锛岀洿鎺ヨ烦鍑哄綋鍓嶇殑for寰幆銆?/p>

break鍦ㄨ繖閲屾槸璺冲嚭寰幆鐨勬剰鎬濄€?/p>

for鍙互宓屽銆?/p>

渚嬶細

涓€涓父鎴忥紝鍓?0鍏虫槸姣忎竴鍏宠嚜韬殑鍒嗘暟锛?br />            21-30鍏虫瘡涓€鍏虫槸10鍒?br />            31-40鍏筹紝姣忎竴鍏虫槸20鍒?br />            41-49鍏筹紝姣忎竴鍏虫槸30鍒?br />            50鍏筹紝鏄?00鍒?br />            杈撳叆浣犵幇鍦ㄩ棷鍒扮殑鍏冲崱鏁帮紝姹備綘鐜板湪鎷ユ湁鐨勫垎鏁?br />            涓ょ鍋氭硶锛歩f宓屽for    for宓屽if

1.if宓屽for

      Console.WriteLine("杈撳叆鍏冲崱");
            int a = int.Parse(Console.ReadLine());
            int b = 0;
            if (a <= 50 && a > 0)
            {
                if (a <= 20)
                {
                    for (int n = 0; n <= a; n++)
                    {
                        b = b + n;
                    }
                }
                else if (a <= 30)
                {
                    for (int n = 0; n <= 20; n++)
                    {
                        b = b + n;
                    }
                    for (int n = 21; n <= a; n++)
                    {
                        b = b + 10;
                    }
                }
                else if (a <= 40)
                {
                    for (int n = 0; n <= 20; n++)
                    {
                        b = b + n;
                    }
                    for (int n = 21; n <= 30; n++)
                    {
                        b = b + 10;
                    }
                    for (int n = 31; n <= a; n++)
                    {
                        b = b + 20;
                    }
                }
                else if (a <= 49)
                {
                    for (int n = 0; n <= 20; n++)
                    {
                        b = b + n;
                    }
                    for (int n = 21; n <= 30; n++)
                    {
                        b = b + 10;
                    }
                    for (int n = 31; n <= 40; n++)
                    {
                        b = b + 20;
                    }
                    for (int n = 41; n <= a; n++)
                    {
                        b = b + 30;
                    }
                }
                else
                {
                    for (int n = 0; n <= 20; n++)
                    {
                        b = b + n;
                    }
                    for (int n = 21; n <= 30; n++)
                    {
                        b = b + 10;
                    }
                    for (int n = 31; n <= 40; n++)
                    {
                        b = b + 20;
                    }
                    for (int n = 41; n <= 49; n++)
                    {
                        b = b + 30;
                    }
                    for (int n = 50; n <= a; n++)
                    {
                        b = b + 100;
                    }
                }
                Console.WriteLine("鍒嗘暟鏄? + b);
            }
            else
            {
                Console.WriteLine("杈撳叆鏈夎");
            }
            Console.ReadLine();

2.for宓屽if


            Console.WriteLine("杈撳叆鍏冲崱");
            int a = int.Parse(Console.ReadLine());
            int b = 0;
            if (a <= 50 && a > 0)
            {
                for (int n = 0; n <= a; n++)
                {
                    if (n <= 20)
                    {
                        b = b + n;
                    }
                    else if (n <= 30)
                    {
                        b = b + 10;
                    }
                    else if (n <= 40)
                    {
                        b = b + 20;
                    }
                    else if (n <= 49)
                    {
                        b = b + 30;
                    }
                    else
                    {
                        b = b + 100;
                    }
                }
                Console.WriteLine("鍒嗘暟鏄? + b);
            }
            else
            {
                Console.WriteLine("杈撳叆鏈夎");
            }
            Console.ReadLine();

for宓屽

            for (int i = 1; i <= 5; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write("鈻?);
                }
                Console.WriteLine();
            }
            Console.ReadLine();

鈻?/span>

鈻?鈻?/span>

鈻?鈻?鈻?/span>

鈻?鈻?鈻?鈻?/span>

鈻?鈻?鈻?鈻?鈻?/span>

 

           for (int i = 1; i <= 5; i++)
            {
                for (int j = 1; j <= (5 - i) + 1; j++)
                {
                    Console.Write("鈻?);
                }
                Console.WriteLine();
            }
            Console.ReadLine();

鈻?鈻?鈻?鈻?鈻?/span>

 

鈻?鈻?鈻?鈻?/span>

 

鈻?鈻?鈻?/span>

 

鈻?鈻?/span>

 

鈻?/span>

 

 

 

 

 

 

            for (int i = 1; i <= 5; i++)
            {
                for (int j = 1; j < i; j++)
                {
                    Console.Write("  ");
                }
                for (int k = 1; k <= (5 - i) + 1; k++)
                {
                    Console.Write("鈻?);
                }
                Console.WriteLine();
            }
            Console.ReadLine();

鈻?鈻?鈻?鈻?鈻?/span>

 

   鈻?鈻?鈻?鈻?/span>

 

      鈻?鈻?鈻?/span>

 

         鈻?鈻?/span>

 

            鈻?/span>

 


            for (int i = 1; i <= 5; i++)
            {
                for (int j = 1; j <= 5 - i; j++)
                {
                    Console.Write("  ");
                }
                for (int h = 1; h <= i; h++)
                {
                    Console.Write("鈻?);
                }
                Console.WriteLine();
            }
            Console.ReadLine();

            鈻?/span>

         鈻?鈻?/span>

      鈻?鈻?鈻?/span>

   鈻?鈻?鈻?鈻?/span>

鈻?鈻?鈻?鈻?鈻?/span>

          

以上是关于寰幆璇彞的主要内容,如果未能解决你的问题,请参考以下文章

cakephp鑾峰彇鏈€鍚庝竴鏉ql璇彞

JS 璋冭瘯璇彞

sql璇彞

linq to sql 鍜?entity framework 杈撳嚭sql璇彞

SQL涔婭NSERT INTO SELECT 鍜孲ELECT INTO FROM 璇彞

SQL-W3School-楂樼骇锛歋QL CREATE INDEX 璇彞