顺序查找

顺序查找,是指从一组顺序数字组中,查找所需要的数字,是否在其中的一种查找方式。其基本形式为:

           首先定义一组数组:

          int[] a = new int[8] { 6, 10, 17, 22, 34, 42, 53, 61 };

          输入你想要查找的数字(将输入的数字字符串形式,转换为32位有符号整数):

          int find = Convert.ToInt32(Console.ReadLine());

         赋值查找为错误:
          bool found = false;

        建立一个for循环,在数组内进行查找:
          for (int i = 0; i <= a.Length - 1; i++)
       {

         如果数组内有与你输入的数字相同的数,则查找会变为正确,输出数字所在位置,并跳转出程序,结束:
             if (a[i] == find)
          {
             found = true;
            Console.WriteLine("找到啦!是第{0}个数", i + 1);
            break;
           }
       }

       如果数组内没有你所输入的数,则查找仍为错误,输出为“没找到!”,程序结束:

          if (found == false)
      {
        Console.WriteLine("没找到!");
      }

原文地址:https://www.cnblogs.com/m-m-g-y0416/p/5414573.html