-4
我试图从int数组中接收最大数字,但它对我来说工作不太好。试图获得最大的数字
for (c = 0; c < 26; c++)
{
printf("%c occurs %d times in the entered string.\n",c+'a',count[c]);
if(count[c] > tempcount1)
{
temp=count[c];
}
tempcount1=count[c];
}
printf("%d",temp);
tempcount1
在程序开始时设置为0。有谁知道问题在我的代码中?
你应该比较tempcount1,然后更新温度? – Parttimereaper
当你只需要一个变量时,你似乎有两个单独的变量,'temp'和'tempcount1'。在if语句中删除'temp = count [c];'并移动'tempcount1 = count [c];'然后在最后打印'tempcount1'而不是'temp'。 –
你是不是应该在内部声明'''tempcount1'''而不在其他地方?什么是'''temp'''? –