How to search an element in an array passing array as arguments?

CODE




How to search an element in an array passing array as arguments?

//Write a program to search an element in an array passing array as arguments…

int main()
{
    int i,n,a[10];
    void search(int *p,int n);
    printf("\n enter N:");
    scanf("%d",&n);
    printf("\n enter array:");
    for(i=0;i<n;i++)
    {
        printf("\n value at a[%d]:",i);
        scanf("%d",&a[i]);
    }
    search(a,n);
}
search(int *p,int n)
{
    int num,i,count=0;
    printf("\n enter the number:");
    scanf("%d",&num);
    for(i=0;i<n;i++)
    {
        if(num==*(p+i))
        {
            count++;
            printf("\n %d present at a[%d]",num,i);
        }
    }
    printf("\n %d is present %d times",num,count);
}


Output:
enter N:4

 enter array:
 value at a[0]:5
 value at a[1]:7
 value at a[2]:9
 value at a[3]:6

 enter the number:5
 5 present at a[0]
 5 is present 1 times

How to search an element in an array passing array as arguments? How to search an element in an array passing array as arguments? Reviewed by Unknown on December 31, 2018 Rating: 5

No comments:

If you have any doubt or query ,comment below:

Programming copyright © 2018-19. Powered by Blogger.