Wednesday, 3 September 2014

                   /*   SEARCH ELEMENT AND PRINT THE INDEX OF ELEMENT*/




#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    FINAL SUMITION










6 comments:

  1. i am seeing everyone's output are same those
    who are uploaded the image of output ...

    ReplyDelete
  2. There is no logic to initialize the variable 'p' with negative '0'. If the elements are in duplicacy manner in the array then your code give the last duplicate element's index value. Take an example of 5 array size and insert elements {2,2,2,2,2}. Your code will give position of 2 is '4'.

    ReplyDelete
  3. all are coping n pasting........

    ReplyDelete

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