If you have n balls, you need to set up two level loops to check if they are collide with each other
code might be similar to the following:
for(int i=0;i for(int j=i;j  check_collision(i,j,x,y);
}
}