You are on page 1of 2

Write a program that reads in a set of positive integers and outputs how many times a particular number

appears in the list. You may assume that the data set has at most 100 numbers and -999 marks the end
of the input data. The numbers must be output in increasing order. For example, for the data:
15 40 28 62 95 15 28 13 62 65 48 95 65 62 65
95 95
The output is:
Number Count
13 1
15 2
28 2
40 1
48 1
62 3
65 3

m
er as
95 4

co
eH w
Answer:

o.
rs e
ou urc
#include <iostream>

using namespace std;


o
aC s

int main()
vi y re

{
int arr[1000],j;
int k=0;
ed d

cout << "Program that reads a set of positive integers and outputs how many times a particular
ar stu

number appears";
cout << " Enter a set of integers (-999 to stop)" << endl;
sh is

for(int i=0; i< 1000; i++) // to initialize each element with 0.


arr[i]=0;
Th

// to input the integer until we get -999 to stop reading the int value.
do
{
cin>> j;

if(j== -999)
break;

arr[j]++;

https://www.coursehero.com/file/78271954/Question-69docx/
k++;
}
while(k<100);

// for printing the value.


for(int i=0;i<1000;i++)
{
if(arr[i]!= 0)
{
cout<< i<<" "<<arr[i]<<"\n";
}
}

m
er as
co
return 0;

eH w
}

o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
sh is
Th

https://www.coursehero.com/file/78271954/Question-69docx/

Powered by TCPDF (www.tcpdf.org)

You might also like