Wednesday, 3 September 2014

search an element and their position in an array

#include<stdio.h>
#include<conio.h>
int main ()
{
int list[100],n,i,x,p;
printf("\n enter the size of the list...");
scanf("%d",&n);
printf("\n enter the element");
for(i=0; i<n; i++)
scanf("%d",&list[i]);
p=0;
printf("\n 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("the list of element %d is at postion %d",x,p);
    else
    printf("\n the element %d is not found in the list TRY AGAIN",x);
    getch();
}




No comments:

Post a Comment

Note: only a member of this blog may post a comment.