Skip to content

Instantly share code, notes, and snippets.

@dd1994
Created May 12, 2014 11:21
Show Gist options
  • Select an option

  • Save dd1994/73ab4d054cf3a9aa0c11 to your computer and use it in GitHub Desktop.

Select an option

Save dd1994/73ab4d054cf3a9aa0c11 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int search(int *a, int, int);
int main(void)
{
int a[10], i, x;
int j = 0;
while(1) {
for (i = 0; i < 10; ++i)
{
scanf("%d", a + i);
}
scanf("%d", &x);
i = search(a, 10, x);
if (-1 == i)
{
printf("Not found\n");
}
else
{
printf("%d\n", i);
}
}
return 0;
}
int search(int list[], int n, int x)
{
int i, j, flag;
for (i = 0, flag = 0; i < n; ++i)
{
if (x == list[i])
{
flag = 1;
return i;
break;
}
}
if (0 == flag)
{
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment