Skip to content

Instantly share code, notes, and snippets.

@ochilab
Created November 15, 2020 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochilab/a0622c27bd2d3a18ca8118abe250494e to your computer and use it in GitHub Desktop.
Save ochilab/a0622c27bd2d3a18ca8118abe250494e to your computer and use it in GitHub Desktop.
C言語による番兵法
int sentinel(){
int test[11]={3,23,5,8,32,6,50,7,4,13};
int target = 50;
test[10]=target; //末尾に検索対象を入れる
while(1){
if(target==test[i]){
printf("見つかりました\n");
break;
}
i++
}
return i==target?-1:i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment