Sunday 29 September 2013

c program to search an element in an array(linear search)

 #include<stdio.h>
#include<conio.h>
#define MAX 50
void main()

{

int a[MAX],n,i,no;
clrscr();
printf("enter the size of array..");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n enter element:%d",i+1);
scanf("%d",&a[i]);
}
printf("enter the element to be searched..");
scanf("%d",&no);
for(i=0;i<n;i++)
{
if(no==a[i])
{
printf("number found at location :%d",i+1);
break;
}
else
{
printf("\n not found.");
}
  }
  getch();
}

No comments:

Post a Comment