Question: ( Count occurrence of numbers ) Write a program that reads at most 1 0 0 integers between 1 and 1 0 0 and counts

(Count occurrence of numbers)
Write a program that reads at most 100 integers between 1 and 100 and counts the occurrence of each number. Assume the input ends with 0.
Example output:
Enter the numbers between 1 and 100 ending with 0:
256543234320
2 occurs 2 times
3 occurs 1 time
4 occurs 1 time
5 occurs 2 times
6 occurs 1 time
23 occurs 1 time
43 occurs 1 time
Could you write the program in C++ please? I'm having issues with my code where it won't display the 1s occurring.
using namespace std;
int main()
{
int counts[100];
int number;
for (int i =0; i 100; i++)
counts[i]=0;
cout "Enter the numbers between 1 and 100 ending with 0: " endl;
cin >> number;
while (number !=0)
{
counts[number -1]++;
cin >> number;
}
for (int i =1; i 100; i++)
{
if (counts[i]>0)
cout (i +1)" occurs " counts[i]
((counts[i]==1)?" time" : " times") endl;
}
return 0;
( Count occurrence of numbers ) Write a program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!