我正在努力使用我的代码来查找数组中出现的数字。如果用户将1230476和10034850作为它们的两个整数提供,则应该显示对于偶数,最大出现次数为0,出现次数为4,最小出现次数为2,6,8,仅出现1次。我没有得到正确的结果,这里的出现次数是我的输出:
How many integers (to be worked on)? 2
Enter integer #1: 1230476
Enter integer #2: 10034850
Occurence of all existing digits --
Digit 0 : 4
Digit 1 : 2
Digit 2 : 1
Digit 3 : 2
Digit 4 : 2
Digit 5 : 1
Digit 6 : 1
Digit 7 : 1
Digit 8 : 1
Occurence of all existing EVEN digits --
Digit 0 : 4
Digit 2 : 1
Digit 4 : 2
Digit 6 : 1
Digit 8 : 1
The even digit(s) that has/have the largest occurrence -
0
And the number of occurrence(s) : 1
The even digit(s) that has/have the smallest occurance -
2
6
8
And the number of occurence(s) : 1
Occurence of all existing ODD digits --
Digit 1 : 2
Digit 3 : 2
Digit 5 : 1
Digit 7 : 1
The odd digit(s) that has/have the largest occurrence -
And the number of occurrence(s) : 1
The odd digit(s) that has/have the smallest occurrence -
5
7
And the number of occurrence(s) : 1
我的代码是:
cout << "\n The even digit(s) that has/have the largest occurrence -";
for (i = 0; i < 10; i += 2) {
mostOccuringEven = digitCount[i] % 10;
if (digitCount[i] != 0) {
if (mostOccuringEven > integersToWorkOn) {
cout << "\n " << i;
}
}
}
cout << "\n And the number of occurrence(s) : " << mostOccuringEven;
这是我第一次发帖,如果我没有做到这一点,请道歉...在这里感谢任何帮助!