number of non same elements

This is a discussion on number of non same elements within the C++ Programming forums, part of the General Programming Boards category; hi
this program is for counting number of nons ame elements in an array of size 5
i think this ...

number of non same elements

hi
this program is for counting number of nons ame elements in an array of size 5
i think this program is specific for array of size 5 this is not general
i want to make a general program, means by changing just 1 or 2 values in the code i can use it for higher size arrays here is my code

let me explain
suppose i have an array of size 5 and i enter these number
1 2 2 4 5
here 1, 4,5 are not same so i say number of non same elements is 3 while number of same elements is 2
so i want to display number of non same elements in the array

hmm... well, if I understand this right, I would suggest that you make use of a std::map<int, size_t>. You just insert into the map and increment the value (i.e., map the elements to their counts). When you are done, you iterate over the map. All keys for which the values are 1 are "non-same".

Let an integer 'x' equal some number of interest, and let integer 'k' equal zero. Then in a loop from j = 0 to array.size()-1 perform a check against each (array[j] == x); If true do nothing, if not true increment k by one. When the loop completes 'k' will represent the number of elements which are not the same as some given value 'x'.

I figure that's not a complete solution for what you're looking to do, but it is a start.

In a problem like this, especially if you're new to algorithms/math/programming, what I recommend you do is you write out the steps that are necessary to complete a task, make it work on paper. Then use what you know of some programming language to implement those steps for a program to execute. Sometimes it helps to think 'out loud' on paper before writing code, that's usually a good way of figuring these things out on your own.