should output "00001". That's fine. However, I am wondering whether there is any way to determine the total number of digits (5 in this example) dynamically during program run-time? It should equal the number of digits (call it max_digits) of the largest number within an integer array, which is not known a priori.
You have two possibilities. The first is that you can generate the format string yourself. The second is that you can use '*' and specify required number of digits as a parameter of printf. For example