#include<stdio.h>
int search(int [],int,int);
main()
{
int i,a[50],s,n,p;
printf("Enter no of elements");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter element to be searched");
scanf("%d",&s);
p=search(a,n,s);
if(p==-1)
{
printf("Element not found");
}
else
{
printf("Position=%d",p+1);
}
}
int search(int a[],int n,int s)
{
int i,p=-1;
for(i=0;i<n;i++)
{
if(a[i]==s)
{
p=i;
break;
}
}
return p;
}
ASSIGNMENT 9)
int search(int [],int,int);
main()
{
int i,a[50],s,n,p;
printf("Enter no of elements");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter element to be searched");
scanf("%d",&s);
p=search(a,n,s);
if(p==-1)
{
printf("Element not found");
}
else
{
printf("Position=%d",p+1);
}
}
int search(int a[],int n,int s)
{
int i,p=-1;
for(i=0;i<n;i++)
{
if(a[i]==s)
{
p=i;
break;
}
}
return p;
}
ASSIGNMENT 9)
TO DEMONSTRATE USE OF 1-D ARRAY AND FUNCTIONS.
No comments:
Post a Comment