0% found this document useful (0 votes)
11 views

Exp 2 A

Uploaded by

handearyan40
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Exp 2 A

Uploaded by

handearyan40
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

//program of linear search

#include<stdio.h>
#include<conio.h>
void main()
{
int x,arr[100],i,j,k,c;
c=0;
clrscr ();
printf("enter number of array element(less than
100)");
scanf("%d",&x);
for (i=0; i<x; i++)
{
printf("enter element no %d", i+1);
scanf("%d",&arr[i]);
}
printf("enter element to be searched:");
scanf ("%d",&k);
for(j=0;j<x;j++)
{
if(arr[j]==k)
{
printf("\nelement %d found at position %d",k,j+1);
c++;
}
if(j==(x-1)&&c==0)
{
printf("\n element not present in array",k);
}
}
getch();
}
//OUTPUT
/*Enter number of array element(less than 100)5
Enter element no 1 23
Enter element no 2 65
Enter element no 3 45
Enter element no 4 21
Enter element no 5 56
Enter element to be searched:56

Element 56 found at position 5


*/

You might also like