Will my nikkor50-200 mm lens for nikon d40x fit and work on my d5100?

Will my nikkor50-200 mm lens for nikon d40x fit and work on my d5100?

No, you have to buy all new lenses every time you buy a new camera.
Of course it will fit. Of course it will work. If you can't find out something so simple for yourself, you should sell the camera and get a crayon and paper.

Do you perhaps mean the 55-200mm?
Nikon f-mount lenses are not camera specific. If the lens will work with your D40x, it will work with the D5100.
http://www.althephoto.com/lenses/con-telephoto.php

It will fit without problems. They have the same mount. As for autofocus, if it didn't with the D40x, it won't either on the D5100.