I doubt you actually need to program anything. There are many programs that do this, specifically wallets.
You can download any wallet and they all keep track of balances of your addresses.
What is the exact thing you are trying to achieve? Why not just use a wallet?