I will only be developing the computation of forces on a given atom (part 1 of <PERSON> answer), for this point is actually a bit tricky and I think it deserves to be a bit more explained. You can find useful remarks in any book of molecular simulation my personal reference being "Computational Simulation of Liquids" from Allen and Tildesley and the "Molecular Dynamics" Lecture Notes on Physics from <PERSON>.
The force of a pair of particles interacting is directed along the vector defined by the difference of the coordinates of the particles. Let's call this vector $\mathbf{r}{ij}$ and the unitary vector with the same direction: $$ \mathbf{r}{ij} = \mathbf{r}i - \mathbf{r}_j\ ;\ \mathbf{n}{ij}=\frac{\mathbf{r}{ij}}{|\mathbf{r}{ij}|}=\frac{\mathbf{r}_{ij}}{r}$$
With $|\mathbf{r}{ij}|=\sqrt{r{ij,x}^2+r_{ij,y}^2+r_{ij,z}^2}=r$
If you compute the force $f$ with regard to $r$ : $$f_{ij} = -\frac{dV}{dr}$$ You will note that :
1. This value is positive when $rr_0$.
2. 649
The force is pushing the atoms away from one another in the first case and getting them closer in the second.
Therefore the force exerced on atom $i$ is opposed in direction to vector $\mathbf{n}{ij}$ as it is defined here. Some authors define it with opposite value, or for example, <PERSON> used $\mathbf{n}{ji}$.
You can then add the force to the total force on the atom $i$ : $$ \mathbf{F}{i} = \sum{j=1\ ;\ j \ne i}^N -f_{ij}\mathbf{n}_{ij}$$
One remark though concerning your algorithm. Given that $f_{ij}=-f_{ji}$ due to <PERSON>'s third law, you can make your loop outside of your function computing the forces. You can actually make your piece of code more like :
void ComputeForces{
for(int i=0;i<N_particles;i++){
for(int j=i+1;j<N_particles,j++){
Computeforce(atm[i], atm[j]);
}
}
In the function ComputeForce, taking two arguments allow you to shorten the loop as you go on and on as you can update the forces on atom $j$ as well. 418