标签:c语言学习
看了看以前写的程序,觉得应该再写一次。
#include<stdio.h> #include<string.h> char* find(char *left, char *right,int len) { char k; char *mid= left + len / 2; printf("k="); scanf("%c", &k); while ((*mid != *left) && (*mid!=*right)) { len /= 2; if (k == *mid) return mid; else if (k < *mid) { right = mid; mid = left + len/ 2; } else { left = mid; mid = left + len / 2; } } return NULL; } int main() { char arr[] = "123456"; int len = 0; len = strlen(arr); printf("%d", find(arr, arr + len - 1, len)); system("pause"); return 0; }
标签:c语言学习
原文地址:http://lzd1995.blog.51cto.com/10973198/1732830