#include<stdio.h>
int search(int a[],int n,int x);
main()
{
int a[100],i,n,ele,f;
printf("\nEnter how many terms=");
scanf("%d",&n);
printf("\nEnter the elements=");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\nThe elements are=");
for(i=0;i<n;i++)
{
printf("%d ",*(a+i));
}
printf("\nEnter the element to be searched=");
scanf("%d",&ele);
f=search(a,n,ele);
if(f==-1)
printf("\nElement not found");
else
printf("\nElement found in position %d",f);
}
int search(int a[],int n,int x)
{
int i,f=0;
for(i=0;i<n;i++)
{
if(a[i]==x)
{
return i;
}
}
return -1;
}
int search(int a[],int n,int x);
main()
{
int a[100],i,n,ele,f;
printf("\nEnter how many terms=");
scanf("%d",&n);
printf("\nEnter the elements=");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\nThe elements are=");
for(i=0;i<n;i++)
{
printf("%d ",*(a+i));
}
printf("\nEnter the element to be searched=");
scanf("%d",&ele);
f=search(a,n,ele);
if(f==-1)
printf("\nElement not found");
else
printf("\nElement found in position %d",f);
}
int search(int a[],int n,int x)
{
int i,f=0;
for(i=0;i<n;i++)
{
if(a[i]==x)
{
return i;
}
}
return -1;
}
No comments:
Post a Comment