completed brute force solution in C