반응형
search
1.소스
#include <stdio.h> int main() { int array[100] ={ 0,-1,100,10,7}; int search = 10; int c; int n; for (c = 0; c < n; c++) { if (array[c] == search) /* if required element found */ { printf("%d is present at location %d.\n", search, c+1); break; } } if (c == n) printf("%d is not present in array.\n", search); return 0; }
2.결과
hacker@HACKER:~/c$ gcc -o search1 search1.c hacker@HACKER:~/c$ ./search1 10 is present at location 4.
반응형
'C 언어' 카테고리의 다른 글
copy file (0) | 2016.07.12 |
---|---|
binary search (0) | 2016.07.12 |
insertion sort (0) | 2016.07.12 |
selection sort (0) | 2016.07.12 |
bubble sort (0) | 2016.07.12 |