Posts

Showing posts from May 22, 2021

Linear Search program in java

Image
 Q. write a program in java to perform a linear search. Ans:- import java.io.*; public class LnearSearch { public static void main(String args[])throws IOException { InputStreamReader in=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(in); int i,s,n,h=0 ; System.out.println("Enter length of Array="); n=Integer.parseInt(br.readLine()); int A[ ]=new int[n]; System.out.println("Enter arrays elemnts ="); for(i=0;i<n;i++) { A[i]=Integer.parseInt(br.readLine()); } System.out.println("Arrays elemnts are ="); for(i=0;i<n;i++) { System.out.println(A[i]); } System.out.println("Enter elemnt which to be searched="); s=Integer.parseInt(br.readLine()); for(i=0;i<n;i++) { if(s==A[i]) { System.out.println("elements is found"); h=1; } } if(h==0) { System.out.println("Element is not found"); } } }                                   if you run in blue-j application then t...

introduction of array / what is array in c++/ what is array in programming

  ARRAY Array it is a reference data type. It can hold several items of the same type that stored at a contiguous memory location.   It consists of contiguous memory locations.   It works on the index number. Since it holds all items on an index basis. Its index number is starting with 0(zero) and last with size-1 or length-1 i.e. if length/size of array is 5 then its index number will be {0,1,2,3,4}. Here it is clear that the last index will be 5-1=4.it means that size-1/length-1. It is used to handle multiple values of the same type at a time. Types of Array There are two types of Array such as- One-dimensional Arrays/single-dimensional Array .   Double-dimensional Arrays/Multi-dimensional Array