wap to input array of n elements input another no.and check whether no.is present if present then print with actual position
Answers
Answer:
import java.util.*;
class Search
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter n ");
int a[]=new int[n];
int flag=0;
System.out.println("Enter "+n+" elements");
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
System.out.println("Enter a number for searching");
int s=sc.nextInt();
for(int i=0;i<n;i++)
{
if(s==a[i])
{
System.out.println("Element found at "+(i+1));
flag=1;
break;
}
}
if(flag==0)
System.out.println("Element not found");
}
}
Thank you
PLS MARK IT BRAINLIEST
The following codes have been written using Python.
n = int(input("Enter the number of elements you'd like to enter: "))
l = list()
for i in range(n):
x = eval(input("Enter the element: "))
l.append(x)
print("The list you've entered: ", l)
c = eval(input("Enter the element you'd like to search for: "))
if c in l:
print(c, "occurs first in", l.index(c))
- append() enables users to add elements to a list.
- index() displays the index position of an element's first occurence.