What you want is called "inverse kinematics", which involves having a mathematical model for the lengths and joints of the arm.
Your program will then take the desired final position and orientation of the "gripper" (if there is one) and calculate the best arm movements to achieve that goal, taking into account mechanically forbidden angles, obstructions, etc.
It is not at all a simple problem, but Google will provide plenty of information.