In the Name of Allah, the All-Merciful, the Mercy-Giving
All praise is due to Allah. Peace and blessings be upon him His Messenger Muhammad.
Niyyah (intention) reposes in the heart. A Muslim should not pronounce his intention when starting an act of worship because, on the one hand, such pronouncement was not the practice of the Messenger of Allah, the best worshipper, nor did he command any of his companions to do so. On the other hand, to pronounce one’s intention when starting an act of worship sounds as unreasonable as to pronounce one’s intention when starting to eat or drink. Once you know of yourself that you are about to do something, your intention follows.
Accordingly, when starting to follow the imam, you just join him in prayer with your inner intention to follow him. If the Prayer contains no loud recitation, then you have to say what you have to say when praying alone. If it contains a loud recitation, then you have to listen to his recitation. Scholars have disagreed whether those behind the imam have to recite surat al-Fatihah in this case or not.
When a person prays alone and then someone comes to join him to form jama`ah, once he knows of that, his intention to be the imam simply follows.
Almighty Allah knows best.