seqsearch.c

来自「这个是简单的初级的算法代码汗 不要在冒了」· C语言 代码 · 共 42 行

C
42
字号
#include <stdio.h>

int seqSearch(int list[],int last,int target,int *locn)
{
  int looker;
  int found;

  looker = 0;
  while (looker < last && target != list[looker])
    looker++;

  *locn = looker;

  if (target == list[looker])
    found = 1;
  else
    found = 0;

  return found;
}

void main()
{
   int list1[10]={45,2,12,14,22,21,5,34,32,9},i;
   int location;

   for(i=0;i<10;i++)
      printf("%d  ",list1[i]);
   printf("\n");

   if (seqSearch(list1,9,22,&location) == 1)
      printf("target is 22,the loacation is : %d",location);
   else
      printf("target is 22,not found!");
      


   getch();
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?