,编程查找该字符是否在字符串,是,给出字符所在的位置,不是,给出没找到#include”stdio.h” #include”string.h” main() { int bot=0,top,mid,flag=0; char str[11]=”achklnprtx”,c; c=getchar(); top= ; while((top-bot)>=0) { ; if(b[mid]==c) { flag=1; ;} else if(b[mid]; else ; } if( ) printf(“%c字符在已知字符串中的位置为%d\n”,c,mid); else printf(“%c字符不在已知字符串中\n”,c);}
#include "stdio.h"
#include "string.h"
main()
{ int bot=0,top,mid,flag=0;
char str[11]="achklnprtx",c;
c=getchar();
top=strlen(str)-1;
while((top-bot)>=0)
{mid=(bot+top)/2;
if(str[mid]==c)
{ flag=1;break;}
else if(str[mid]<c)bot=mid+1;
else top=mid-1;
}
if(str[mid]==c)
printf("%c字符在已知字符串中的位置为%d\n",c,mid);
else printf("%c字符不在已知字符串中\n",c);
}