I have experienced first-hand the shock of discovering just how hard university is, but pushing yourself harder and harder until you break is not the answer. You need to be smarter about how you work, you need to develop proper study habits, and you need to get over your fear of asking for help. But at the end of the day, grades are just grades. Once you finish university and get your first job, none of this will matter anymore.
University is far harder than programming jobs, so don't judge yourself too harshly for struggling. Many things are more important in life. Remember to enjoy the most intense learning experience you will ever experience, and don't forget to look after your own health.