#include<stdio.h>
main()
{
int list[100],n,i,x,p;
printf("enter the size of the list =");
scanf("%d",&n);
printf("enter the elements=");
for(i=0;i<n;i++)
scanf("%d",&list[i]);
p=0;
printf("enter the element to be searched");
scanf("%d",&x);
for(i=0;i<n;i++)
{
if(list[i]==x)
{
p=i+1;
}
}
if(p>0)
printf("position of the element %d is %d",x,p);
else printf("try again");
getch();
}
output
enter the size of the list = 6
enter the elements=42
55
66
87
123
142
enter the element to be searched87
position of the element 87 is 4
main()
{
int list[100],n,i,x,p;
printf("enter the size of the list =");
scanf("%d",&n);
printf("enter the elements=");
for(i=0;i<n;i++)
scanf("%d",&list[i]);
p=0;
printf("enter the element to be searched");
scanf("%d",&x);
for(i=0;i<n;i++)
{
if(list[i]==x)
{
p=i+1;
}
}
if(p>0)
printf("position of the element %d is %d",x,p);
else printf("try again");
getch();
}
output
enter the size of the list = 6
enter the elements=42
55
66
87
123
142
enter the element to be searched87
position of the element 87 is 4
all has same problem ..........in p ...
ReplyDeletecheck where u assign p
all are coping
ReplyDelete