C 언어138 search search 1.소스 #include 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$ ./searc.. 2016. 7. 12. insertion sort insertion sort 1. 소스 #include int main() { int n, array[1000], c, d, t; printf("Enter number of elements\n"); scanf("%d", &n); printf("Enter %d integers\n", n); for (c = 0; c < n; c++) { scanf("%d", &array[c]); } for (c = 1 ; c 0 && array[d] < array[d-1]) { t = array[d]; array[d] = array[d-1]; array[d-1] = t; d--; } } printf("Sorted list in ascending order:\n"); for (c = 0; c 2016. 7. 12. selection sort selection sort 1. 소스 #include int main() { int array[100], n, c, d, position, swap; printf("Enter number of elements\n"); scanf("%d", &n); printf("Enter %d integers\n", n); for ( c = 0 ; c array[d] ) position = d; } if ( position != c ) { swap = array[c.. 2016. 7. 12. bubble sort bubble sort (버블 소트 ) 1. 소스 #include int main() { int array[100], n, c, d, swap; printf("Enter number of elements\n"); scanf("%d", &n); printf("Enter %d integers\n", n); for (c = 0; c array[d+1]) /* For decreasing order use < */ { swap = array[d]; array[d] = array[d+1]; array[d+1.. 2016. 7. 12. 이전 1 ··· 3 4 5 6 7 8 9 ··· 35 다음