Check out The Unix Programming Environment it's a great read for beginers, and goes well with FreeBSD.
Once you get a hold of your environment you'll be able to apply any acquired programming knowledge to your system.
Also check out the rest of the FreeBSD Documentation. There's sections on Programming under FreeBSD.
As root run shutdown -h now to powerdown your machine. But if you are using a recent version for FreeBSD and ACPI and your hardware is all kosher you should be able to turn the system of with the power switch on the case/mainboard.
Out of curiosity what version of FreeBSD are you running?
A simple uname -r will tell us.