///this code only works when the array value is less then 3000;
#include <stdio.h>
int main()
{
int i,n,total=3000;
int a[100],check;
int *array =(int *) calloc(total,sizeof(int));
printf("Please Enter Array Size: ");
scanf("%d",&n);
printf("Please Enter Array Element:
");
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
int pos = a[i];
array[pos] += 1;
}
printf("
Please Enter Which Element You Want to Search: ");
scanf("%d",&check);
printf("
There are %d time %d have in the array.
",array[check],check);
return 0;
}
Output
Please Enter Array Size:5
Please Enter Array Element:
1 4 1 5 1
Please Enter Which Element You Want to Search:1
There are 3 time 1 have in the array.
Add your comment