Wednesday, 3 September 2014

test1

#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\n");
    for(i=0;i<n;i++)
    {
    scanf("%d",&list[i]);
    }
    p=-1;
    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("%d is found at index %d ",x,p);
      }
      else
       {
         printf("%d not found in the list try again",x);
        }
    getch();
    return 0;
    }


output:enter the size of list.....5
enter the element
56
78
90
43
45
enter the element to be search 90
90 is found at index 2

enter the size of list.....3
enter the element
50
60
70
enter the element to be search10
10 not found in the list try again

No comments:

Post a Comment

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