#include<stdio.h>
#include<conio.h>
int search(int *,int,int);
void main()
{
int num[100],loc=-1,i,n,ele;
clrscr();
printf("enter the number of elements to be inserted:");
scanf("%d",&n);
printf("\nenter the elements :");
for(i=0;i<n;i++)
scanf("%d",&num[i]);
printf("\n enter the element to be searched:");
scanf("%d",&ele);
loc=search(num,ele,n);
if(loc<0)
printf("\n elements not found ");
else
printf("elements found at %d position",loc+1);
getch();
}
int search(int num[],int item,int n)
{
int i;
for(i=0;i<n;i++)
{
if(num[i]==item)
return i;
}
return -1;
}
#include<conio.h>
int search(int *,int,int);
void main()
{
int num[100],loc=-1,i,n,ele;
clrscr();
printf("enter the number of elements to be inserted:");
scanf("%d",&n);
printf("\nenter the elements :");
for(i=0;i<n;i++)
scanf("%d",&num[i]);
printf("\n enter the element to be searched:");
scanf("%d",&ele);
loc=search(num,ele,n);
if(loc<0)
printf("\n elements not found ");
else
printf("elements found at %d position",loc+1);
getch();
}
int search(int num[],int item,int n)
{
int i;
for(i=0;i<n;i++)
{
if(num[i]==item)
return i;
}
return -1;
}
This page is helpful,thanks...
ReplyDelete