Computer Science, asked by jainkashish7396, 1 year ago

Write a function solution that accepts a sorted array of numbers a, size of the array n and the element to search

e. the function should return the index of the element.

Answers

Answered by lichidash48pbhfh2
0
import java.util.*;
class array
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the size of array");
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<a.length;i++)
{
System.out.println("Enter the elements:");
a[i]=sc.nextInt();
}
System.out.println("Enter the element to search:");
int search=sc.nextInt();
for(i=0;i<a.length;i++)
{
if(a[i]==search)
{
System.out.print(i);
break;
}
}
}


Similar questions