C version of k means complete