fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main () {
  5.  
  6. /* an array with 5 rows and 2 columns*/
  7. int a[5][2] = { {0,1}, {2,3}, {4,5}, {6,7},{8,9}};
  8. int i, j;
  9. int value = 6;
  10. /* output each array element's value */
  11. for(i=0; i < 5; i++)
  12. {
  13. if (a[i][0] <= value && value <= a[i][1])
  14. { cout << a[i][0] << a[i][1] << "In if";
  15. break;
  16. }
  17. }
  18. if (i >= 5)
  19. cout << "Elemet not present";
  20.  
  21. else
  22. {
  23. cout << "'Element is present at" << i;
  24. int start = i*2+1;
  25. int end = start + 2;
  26.  
  27. while (start <= end)
  28. {
  29. int midle = (start + end) / 2;
  30.  
  31. int row = midle / 2;
  32. int col = midle % 2;
  33.  
  34. if (a[row-1][col] == value)
  35. {cout << "found element" << a[row-1][col];
  36. return 0;}
  37. if (a[row-1][col] < value)
  38. start = midle + 1;
  39. else
  40. start = midle - 1;
  41. }
  42. }
  43. return 0;
  44. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
67In if'Element is present at3found element6