cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Count Number of Data
Count Number of Data
May 14, 2012 at 10:10am UTC
enormousdreamer
(2)
How can I count the number of data in array
Example:
In a class with 20 pupils the heights of the individual pupils, in centimeters, are:
175, 167, 160, 164, 183, 187, 188, 179, 176, 175,
169, 175, 176, 178, 165, 160, 173, 165, 187, 178
The program should read in all the numbers and make a table like this:
height number of pupils
160 2
164 1
165 2
167 1
... ...
... ...
188 1
May 14, 2012 at 10:18am UTC
Gaminic
(1621)
If you sort the array, you'll get all equal values right next to each other. Then, a simple loop will be able to count the number of occurences.
May 14, 2012 at 10:37am UTC
enormousdreamer
(2)
I really new in c++
would you mind ti give me the code ?
May 14, 2012 at 10:40am UTC
Gaminic
(1621)
Yes, I would mind.
This is most likely homework. If I give you working code, you will learn nothing and you'll never be able to solve basic problems like this one yourself. Instead, if you just spend 30 minutes thinking on it, the next time will be much easier.
Topic archived. No new replies allowed.