Write a program that search a number in an array and also display number of times it appears.

#include<stdio.h>
search(int * arr, int n, int m)
{

int l=0;
while(n>0)
{ if(m== *arr)
l++;
n--;
arr++;

}
return l;
}

main()
{ int n, m,i=0,a[100],l;
printf("\nEnter the dimension of array:: ");
scanf("%d",&n);
printf("\nEnter the elments of array:: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nEnte the number you want to search:: ");
scanf("%d",&m);
l=search(a,n,m);
printf("\nArray:: ");
for(i=0;i<n;i++)
printf("%d ",a[i]);
if(l!=0)
printf("\nThe number is found and %d times it appears in array\n", l);
else printf("\n number not found!!!\n");
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s