Even Dev-C++ should return a warning about using an uninitialized variable. For all we know, j could be a negative number randomly pulled out of memory. The reason that you will get repeating numbers...