#include<stdio.h>
int main()
{
int list[100],n,i,x,p;
printf("enter the size of list");
scanf("%d",&n);
printf("enter the element");
for(i=0;i<n;i++)
scanf("%d",&list[i]);
p=0;
printf("enter the element to be search");
scanf("%d",&x);
for(i=0;i<n;i++)
{
if(list[i]==x)
p=i;
}
if(p>0)
printf("index of element %d is %d",x,p);
else
printf("try again");
getch();
return 0;
}
output----
enter the size of list 5
enter the element 4
3
2
1
7
enter the element to be search 4
endex of element 4 is 1
int main()
{
int list[100],n,i,x,p;
printf("enter the size of list");
scanf("%d",&n);
printf("enter the element");
for(i=0;i<n;i++)
scanf("%d",&list[i]);
p=0;
printf("enter the element to be search");
scanf("%d",&x);
for(i=0;i<n;i++)
{
if(list[i]==x)
p=i;
}
if(p>0)
printf("index of element %d is %d",x,p);
else
printf("try again");
getch();
return 0;
}
output----
enter the size of list 5
enter the element 4
3
2
1
7
enter the element to be search 4
endex of element 4 is 1
No comments:
Post a Comment
Note: only a member of this blog may post a comment.