我正在尝试编写一个C程序来打印数组中给定数字的重复次数。什么值得我作为输入,该函数返回值只有0给我..可能是错误..代码附加
#include<Stdio.h>
#include<conio.h>
int occurence(int n, int arr[], int x);
void main()
{
int x,arr[100],n,i;
clrscr();
printf("\nEnter the number of elements: ");
scanf("%d",&n);
printf("\nEnter the elements:");
for(i=0;i<n;i++)
{
scanf("%d",arr[i]);
}
printf("\nEnter the element to be searched for repetitions: ");
scanf("%d",&x);
printf("%d",occurence(n,arr,x));
getch();
}
int occurence(int n,int arr[100], int x)
{
int i,rep=0;
for(i=0;i<n;i++)
{
if(x == arr[i])
{
rep++;
}
}
return rep;wenter code here
}
答案 0 :(得分:0)
问题出在第13行,它应该是scanf(“%d”,&amp; arr [i]);