program 1

import java.util.*;

public class MyClass {

    public static void main(String args[]) {

        Scanner in = new Scanner (System.in);

      

      int n, ns, lb =0, ub =9, p=0,k=0;

      int m[] = new int [10];

      

      System.out.println("Enter the array");

      for (int i =0; i<10; i++){

          m[i] = in.nextInt();

      }

      System.out.println("enter number to be searched");

      ns = in.nextInt();

      

      while (lb<ub){

      p = (lb+ub)/2;

      if (m[p]<ns)

      lb = p+1;

      if (m[p]>ns)

      ub = p-1;

      if (m[p] == ns){

      k =1;

      break;

    }

      }

      if (k==1)

      System.out.println("Search successful");

      else

      System.out.println("Not");

      

    }

}

Comments

Popular posts from this blog

'Tradition is an obstacle to progress.' Express your views either for or against this statement.

Unveiling the Significance of "Hearts and Hands" in O. Henry's Short Story

Appearances Can Be Deceptive: A Tale of Mistaken Identity