编写自定义函数,函数原型为int find(int *a,int n,int x);。该函数的功能是在含有n个元素的数组a中统计元素值等于x的个数。要求在main()函数中输入20个数组元素以及要查找的整数x,并调用find函数来得到并输出数值为x的元素个数。
好哥哥们,我打算先写出来之后再把自定义函数写出来,但是我现在输出的x是乱码,求求好心人帮帮我
#include<stdio.h>
int main()
{
int n, a[20], i, * p, s, x=0;
p = a;
printf("Please enter the number of elements :");
scanf("%d", &n);
printf("Please enter %d integers:", n);
for (i = 0; i < n; i++)
{
scanf("%d", p++);
}
printf("Please enter the number you are looking for :");
scanf("%d", &s);
p = a;
for (i = 0; i < n; p++,i++)
{
if (*p = s)
{
x++;
}
printf("%d", &x);
}
return 0;
}