For Online Computer Support, Ask a Computer Technician
Hello and thank you for your question. I look forward to assisting you today. Can you tell me what type of computer it is please?
If this is a laptop computer then it could be the power supply failing. A faulty fuse either works or it doesn't. If your computer is a laptop and has a removable battery, try removing it and use only the power supply to see computer will remain powered on. Let me know what happens please.
Then one way to resolve it would be to use an Uninterruptible Power Supply. That will maintain a constant voltage and depending on the model, will also monitor and log the AC supply to indicate the date and time of any anomalies. Check this LINK if you are unsure what I am referring to.