Wednesday 2 July 2014

Linear search

#include<conio.H>
#include<stdio.h>


main()
{
int arr[10],i,j,s,n,pos,flag=0;
printf("enter the size of the array");
scanf("%d",&n);
arr[n];
printf("enter the values of element of array");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("the array you entered is this:");
for(i=0;i<n;i++)
{
printf("%d",arr[i]);
}

printf("\n enter the number you want to search in array");
scanf("%d",&s);
for(i=0;i<n;i++)
{
if(arr[i]==s)
{
flag=1;
pos=i;
printf("this number is in this array at possition %d",pos);
}
}
if(flag==0)
printf("this number does not exist in the array");
getch();
return 0;

}

No comments:

Post a Comment