Class 10th ICSE

Q.5

5. WAJP to search for an element given by the user in an integer array of size of 10 elements using Linear search technique. If the element is found print its location.

Solution :- 

import java.util.*;
class p5{
public static void main(){
Scanner sc =new Scanner(System.in);
int i,pos=0,flag=0;
int a[]=new int[10];
for(i=0;i<10;i++){
System.out.println(“Enter number”);
a[i]=sc.nextInt();
}
System.out.println(“Enter number you want to search”);
int num=sc.nextInt();
for(i=0;i<10;i++){
if(a[i]==num){
pos=i;
flag=1;
break;
}
}
if(flag==1){
System.out.println(“Number “+num+” is present at location “+(pos+1));
}
else
System.out.println(“Number not found”);
}
}

Fun & Easy to follow
Works on all devices
Your own Pace
Super Affordable

Popular Videos

Play Video

UX for Teams

Learn the basics and a bit beyond to improve your backend dev skills.

ava4.png
Chris Matthews

Designer

Play Video

SEO & Instagram

Learn the basics and a bit beyond to improve your backend dev skills.

ava4.png
Chris Matthews

Designer