Wednesday, 3 September 2014

//write the program to check the element to be search in the array.


#include<stdio.h>   //this is a header file
#include<conio.h>
int main() //main function declared as an interger
{
    int list[100],n,i,x,p; /* list[100] is defined the size of an array*/
    printf("enter the size of the list :\n");
    scanf("%d",&n); /* here we initialise the size of an array */
    printf("enter the elements :");
    for(i=0;i<n;i++) /* here for loop is used to initialise the element in array according to condition */
    scanf("%d",&list[i]);
    p=0;
    printf("enter the elements to be search :");  //what's element you want to search in array.
    scanf("%d",&x);
    for(i=0;i<n;i++)
    {
                    if(list[i]==x)
                    {
                                  p=i;
                    }
    }  //for loop
    if(p>0)//check the element is greater than 0 and is available in array
    printf(" %d the elements is at position %d  ",x,p);
    else
    printf("try again"); // if condition is Not satisfied than print this statement
    getch();
    return 0;
} //main function




                                                                    
                                                                  -: OUTPUT :-

                                 

No comments:

Post a Comment

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