How Can I Improve at Programming When C Exercises Feel Too Difficult?

0
0
Asked By MellowRaven42 On

I'm a college freshman with no previous coding experience. I started learning Python about a week before college began, but I still don't feel confident. Now my class is teaching C, and syntax such as i++ is getting mixed up with Python.

We were asked to calculate sin(x) using the series x - x^3/3! + x^5/5! ... with loops, and I couldn't figure out how to approach it in either language. My classmates had already studied programming in school and considered this kind of exercise standard, so I'm worried that I'm falling behind. I also recently struggled to realize that nested loops were needed for a multiplication table and couldn't solve a similar Floyd's triangle exercise without seeing the solution.

I've tried online courses in both C and Python, but they didn't cover many examples like these. I often understand a solution after seeing it, but I don't know how to come up with the idea on my own. What should I do to build my problem-solving skills and keep up with my class?

3 Answers

Answered By QuietMaple19 On

Before writing code, describe the solution in plain language or on paper. For a multiplication table, you could say: choose a row number, multiply it by every number from 1 through 10, print those results, then move to the next row. Once the instructions are clear, the loops are mainly a translation of that process.

Do the same with harder questions: list the inputs, the expected output, a few manual examples, and the repeated steps. If you cannot explain the process without code, you probably need to break the problem down further.

Answered By BrightCedar7 On

You’re not behind just because you’re starting from zero. Programming problems often seem impossible until you learn to break them into smaller patterns. For a series such as sine, write out the first few terms by hand, identify what changes from one term to the next, then use a loop to calculate and add one term at a time. Test with a small value of x and compare the result with a calculator.

For nested loops, draw the expected output first. In a multiplication table, the outer loop can select the row from 1 to 10, while the inner loop prints the products for that row. Start with tiny exercises and focus on C for now instead of constantly switching between C and Python.

MellowRaven42 -

I still often need to see the solution before I understand the pattern, especially with multiplication tables and Floyd’s triangle. I’ll try starting with smaller versions and writing the output down first.

Answered By NorthStarV6 On

Since you’re learning two languages, make your own comparison sheet. For example, record that incrementing can be written as i = i + 1 in both languages, while C also allows i++ or ++i. Note that i++ and ++i differ when the expression’s value is used: one returns the old value and the other returns the new value.

The sheet should be something you build yourself, not a reference copied from somewhere else. Also, if you know how to solve an exercise in Python, first write the logic there or in plain language, then translate it into C. Understanding the algorithm matters more than remembering syntax immediately.

SilverKite28 -

Also remember that i += 1 is another clear way to increment in C. You don’t need to use the shorter ++ form until you understand what it does.

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.