Adding Salt n Pepper noise into an Image manually
It seems that the final image is in the variable "b". Observe that the max (salt) and min (pepper) values are respectively 1 and 0. This indicates that your original image needs to be an intensity image with graylevels normalized to [0,1]. This may be the reason why you don't see a sensible result when you display "b" as an image.

In case your image is grayscale {0,...,255} i.e. 8-bit unsigned integer format (unit8), you can change your code to assign 0 and 255 instead of 0 and 1.

I suggest you read the documentation on various image storage types here: http://www.mathworks.com/help/toolbox/images/f14-13543.html

It can get pretty confusing at times, mainly because there are so many names (intensity image, grayscale image, RGB, HSV, binary image, indexed image, etc.)