我一直在尝试编写一个将输入存储到数组中然后允许我打印出来的程序。它还让我知道哪个数字最大。我想弄清楚的是如何让我的程序告诉我输入数组中最大数字的次数(出现次数)。到目前为止,这是我的代码。截至目前,这段代码输出了我输入到数组中的数字,数组中最大的元素,以及我输入的每个数字的出现(数字的出现是不正确的)。总的来说,每个数字的出现次数都是 0。这显然是不正确的。同样,我需要我的程序显示最大的数字(它确实如此)和仅最大数字的出现。欢迎所有建议、提示或想法。谢谢你。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
int main()
{
int arrayNum[15];
int a;
int max=0;
int location;
for( a=0; a < 15; a++)
{
printf("Enter element %d:", a);
scanf("%d",&arrayNum[a]);
}
for(a=0; a < 15; a++)
{
printf("%d\n", arrayNum[a]);
}
for (a = 1; a < 15; a++)
{
if (arrayNum[a] > max)
{
max = arrayNum[a];
location = a+1;
}
}
printf("Max element in the array in the location %d and its value %d\n", location, max);
for(a=0; a<15; a++)
{
if(arrayNum[a+1] == arrayNum[a])
continue;
else
printf("Number %d: %d occurences\n", arrayNum[a]);
}
return 0;
}