You have one loop to do the counting (as you are now).

You have another loop following to print all those seen[i] values which are non-zero.