C Program On How To Search Elements - Linear Search

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

void main()

{
int arr[10],i,j,src,index,flag=0;
clrscr();
printf("Enter any 10 Elements in the ARRAY  : ");

for(i=0;i<10;++i)

{
scanf("%d",&arr[i]);
}

printf("\nEnter The Element to be searched  : ");

scanf("%d",&src);

for(j=0;j<10;++j)

{
if(arr[j]==src)
{
      index=j;
      flag=1;
    break;
}

}


if(flag==0)

printf("Element Not Found !!!");

else

printf("Element Found At %d Index",index);

getch();


}
Share on Google Plus

About Akash Manhas

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment