Always remember that math and programming are hard the same way weightlifting is hard: it is hard for everyone who does it, especially when you are doing it right. Just like in weightlifting, to grow you must push yourself to the point of failure. Struggling is not a sign of lack of ability; it is a sign that you are going through the normal and healthy process that everyone goes through. Deciding you are not a “math person” or “programming person” after struggling is like deciding you cannot be good at weightlifting because you experienced the weight feeling heavy.
You may not believe it but for most of my time in high school I was a bad student, at one point even being rejected from a calculus class. I was disengaged, disorganized, and apathetic. Nobody thought that I could be successful, even myself. However I eventually decided to change my attitude, and subsequently became a straight A student and excelled at mathematics. I never forgot about this experience, and for this reason I believe in every student and never count anyone out. I will always work to encourage students and advocate for outsiders.
You are capable and you are worthwhile. Do not let failure discourage you. Every butterfly begins as a caterpillar.