0

我不知道如何计算输入最大数字的次数。请帮忙。如果我将 s 初始化为 0,它不会计算第一个数字(如果它是最高的)。

#include <stdio.h>


int main (void)
{

    int times=0,n,m,i,max;

    printf("How many numbers(n) you going to enter:\n");
    scanf("%d",&n);

    printf("Enter the numbers:\n");
    scanf("%d",&m);

    max=m;

    for(i=1;i<=n;i++)
    {
    scanf("%d",&m);
    if(m==max)
    times++;
    if(m>max)
    max=m;

    }
    printf("The Largest Number is %d and was entered %d times",max , times);

return 1;
}
4

1 回答 1

2

您需要重置times1

if(m == max) {
    times++;
} else if(m > max)
    max = m;
    times = 1;
}

并将其初始化为1

int times = 1, n, m, i, max;
于 2012-12-12T03:30:34.083 回答