Re-write double for-loop with C