Eating the right foods at right intervals and following an appropriate diet, are the key factors to gain weight. Working out alone is not going to do the trick. You need to exercise your muscles to encourage them to grow, but you also need to provide them with the right nutrition and diet.
The most important factor in muscle building is nutrition. Your nutrition should be based on carbohydrates and protein. Why? Carbohydrates are a perfect source of energy for your body and your body uses protein to repair and grow your muscles. You can’t expect your muscles to grow just because you work out. Your muscles need their fuel. And they need that fuel regularly.