how does the formation of secondary and primary rainbow occurs?
Rainbow forms when sunlight hits the water droplets suspended in the atmosphere and undergoes total internal reflection. When the sunlight comes out of the drop it disperses, where the drop acts like a small prism. This dispersion or breaking up of light into several colors is what forms the Rainbow.
In a primary rainbow the the sunlight is internally reflected once while in a secondary rainbow the sunlight is internally reflected twice. Also, the secondary rainbow is a lot less intense and forms at a separation of about 10 degrees from the primary rainbow.