I like to know whether it is possible to \"write a program or algorithm\" to find the time complexity of any given program
No. It's not possible. This is a form of the halting problem.