Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int mat[n][m];
- int t=n-1, b = 0, l = 0, r = m -1, flag = 0,num; //num is the we search for
- while(t>=b && l <= r)
- {
- if(mat[t/2][r/2]<num)
- {
- break;
- }
- if(mat[t/2][r/2]==num)
- {
- printf("[%d %d]",t/2,r/2);
- flag = 1;
- break;
- }
- if(mat[t][r/2] == num)
- {
- printf("[%d %d]",t,r/2);
- flag = 1;
- break;
- }
- if(mat[t/2][r] == num)
- {
- printf("[%d %d]",t/2,r);
- flag = 1;
- break;
- }
- if(mat[t/2][0] == num)
- {
- printf("[%d %d]",t/2,0);
- flag = 1;
- break;
- }
- if(mat[0][r/2] == num)
- {
- printf("[%d %d]",0,r/2);
- flag = 1;
- break;
- }
- if(mat[t/2][r/2] > num) //first quarter
- {
- t=t/2;
- r=r/2;
- continue;
- }
- else if(a[t/2][0] > num) //second quarter
- {
- t=t/2;
- l=r/2;
- continue;
- }
- else if(a[0][r/2] > num) //third quarter
- {
- b=t/2;
- r=r/2;
- continue;
- }
- else if(a[0][r/2] > num) //fourth quarter
- {
- b=t/2;
- l=r/2;
- continue;
- }
- }
- if(!flag) printf("NOT FOUND");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement