c++ - count specific number of elements -
for example, if have array of 5 inputted elements, how count how many times specific value entered if value has been established in variable.
input: 4 4 4 1 2
if click
defined 4
how count how many times click
used in array? makes sense. thanks
this how c style arrays.
int i; int count = 0; for(i = 0; < arraysize; ++i) { if(array[i] == click) ++count; }
arraysize size of statically allocated array, array
array variable , click value looking for. in count
count of variable saved.
Comments
Post a Comment