what can be the problem when pc comes on and off for few seconds
You should post whether it is failing the POST (did you hear any beeps before it shuts off). Have you made any changes to the computer, are fans/HDD spinning, are we talking 2 secs or 30 secs later. Just few seconds i'm leaning toward PSU/ failing post, if its taking a while then maybe your cpu cooler has failed.
If it comes on for a second or two and then goes off and then powers on and boots normally, then it could be nothing, some boards like my Asus P5Q, do this to precharge the capacitors so as not to shock the system with a large current draw.