How Can I Get Better at Solving Beginner C Problems?

0
0
Asked By MellowQuasar42 On

I'm a college freshman with no previous coding experience. I started learning Python shortly before college, but I still feel uncomfortable writing programs. Now that my classes are teaching C, syntax such as i++ is getting mixed up with Python.

One assignment asked us to calculate sin(x) using the series x - x^3/3! + x^5/5! and so on, using loops. I couldn't figure out how to approach it in either language. My classmates had learned programming in school and seemed to consider this and similar problems standard.

More recently, I couldn't work out that printing multiplication tables required nested loops, and I also struggled with a Floyd's triangle exercise until I saw the solutions. I'm worried that I'm not developing the ability to recognize the approach on my own. What should I do to improve? Should I focus only on C for now, and how can I learn to break these problems down instead of immediately looking at the solution?

2 Answers

Answered By NorthwindPanda58 On

It can help to make your own comparison sheet for C and Python. Record small concepts with examples, such as incrementing a variable: in either language you can write i = i + 1, while C also allows i++ or ++i. The two forms differ when the value of the expression is used, so learn that distinction, but don’t let shorthand distract you from the underlying logic.

If you know how to solve an exercise in Python, first write the algorithm there or in plain English, then translate it into C. If you cannot solve it in Python either, work it out on paper as instructions for another person. Writing this comparison sheet yourself will make the syntax differences easier to remember.

CuriousMaple31 -

The main goal should be understanding the algorithm rather than memorizing every shortcut. Once the steps make sense, the C syntax can be looked up and practiced separately.

Answered By PlainspokenOak19 On

Write the solution in ordinary language before writing code. Don’t begin by guessing syntax. For example, describe a multiplication table as: choose a row, multiply that row by every column value, print the results, then move to the next row. Once the instructions are clear, loops become a way to repeat those instructions.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.