#include<stdio.h>
#include<conio.h>
int main()
{
int list[100], n,i,x,p;
printf("Enter the size of the list\n");
scanf("%d",&n);
printf("Enter the element\n");
for(i=0;i<n;i++)
scanf("%d",&list[i]);
p=0;
printf("Enter the element to search\n ");
scanf("%d",&x);
for(i=-1;i<n;i++)
{
if(list[i]==x)
p=i;
}
if(p>=0)
printf("position of element %d is %d\n",x,p);
else
printf("try again");
getch();
return 0;
}
Enter the size of the list
6
Enter the element
45
56
23
43
31
30
Enter the element to search
43
position of element 43 is 3
#include<conio.h>
int main()
{
int list[100], n,i,x,p;
printf("Enter the size of the list\n");
scanf("%d",&n);
printf("Enter the element\n");
for(i=0;i<n;i++)
scanf("%d",&list[i]);
p=0;
printf("Enter the element to search\n ");
scanf("%d",&x);
for(i=-1;i<n;i++)
{
if(list[i]==x)
p=i;
}
if(p>=0)
printf("position of element %d is %d\n",x,p);
else
printf("try again");
getch();
return 0;
}
Enter the size of the list
6
Enter the element
45
56
23
43
31
30
Enter the element to search
43
position of element 43 is 3
No comments:
Post a Comment
Note: only a member of this blog may post a comment.