Anyway carrying on with the reason behind why most living things feel pain, there seems to be no special evolutionary reason why we feel pain, however our evolution has incorporated this stimulus in our system. If you still want a reason, it goes back to the idea of survival that I have mentioned before...all living things want to live. No animal can self-destroy itself. Imagine that you strictly follow these two points. Now assume you are confronted by a grizzly bear for the first time. You or the other individuals of your species have not come across a situation like this before. Now if the bear jabs you with its paw, which is generally an unpleasant experience, you immediately feel the urge to run away from the bear as far as possible and stay clear. You feel pain and you would want to avoid a second possibility of that event. It is here that the idea of fear makes sense. Fear would not seem to fit in if it were not for something like nociperception.
One other small point to note here. You can think of fear as a program, but nociperception cannot be thought of in that way. Fear is a kind of behaviour. We are able to perceive it with one or more of our senses. The effect of fear is visible. On the other hand nociperception is hidden. We only come to feel pain. Nocipercetion induces a behaviour. It could be anger, fear or sometimes even laughter! However I am linking the phenomenon of nociperception to fear.
You may want to ask if fear is a consequence of this phenomenon called nociperception. The answer is
no its not. I don't think it is logical to think of it that way. I'd rather believe that the combination of nociperception and fear resulted in a successful genetic make or a genotype. This logically means if you had a genotype with only one of either the chances of that type becoming successful in evolutionary terms is relatively low.