@taroon
Hi taroon, welcome to Bytes. We love to help people and provide directions, but are not here to write code for people. I believe in some places people get paid for that, but seeing as we don't get paid, everything is out of the goodness of our hearts...
Have a look at the function Dorm gave you, try it out, post your code and then tell us why it's not working or what it should be doing and we can help you out.