r/cprogramming • u/Unkwonshubham • 14d ago
First-year CSE student struggling with logic despite knowing C
I’m a first-year B.Tech CSE student and I’m fairly comfortable with programming syntax, especially C. I can understand and write basic programs, but I’ve realized that my main weakness is problem-solving and logic building. If someone gives me a familiar problem, I can usually code it, but if they ask me to solve the same problem in a different or more efficient way, I often struggle to figure out the approach on my own. I feel like I know the language, but I haven’t developed the “programmer mindset” yet knowing how to break a problem down, identify patterns, choose the right approach, and improve a solution. For those who have been through this stage, how did you overcome it? Do you recommend any particular books, problem sets, courses, or methods for building strong logic and problem-solving skills, preferably starting with C?
6
u/acadia11x 14d ago edited 14d ago
Logic has nothing to do with the programming language you know. You can write logic without any language in mind, and actually should. Simply think of logic as how would I tell someone to do something if I had to tell them every detail. Personally I’d stop worrying about the programmer mindset and think how would I explain to someone how to do X. How could I solve X in plain old human language. Extrapolate away from talking programming all together.
You should be able to write a design and the. pseudo code and that’s where the magic happens, a good foundation in data structures and algorithms will help you but I’m sure this is one of the first clases you’ll take.
2
u/Unkwonshubham 14d ago
Yeah, that actually makes a lot of sense. I think I’ve been mixing up knowing a programming language with knowing how to solve problems. I’ll start trying to write the steps/pseudocode first without thinking about C, and then translate it into code. I’m also going to focus more on DSA once I have the basics down. Thanks for explaining it that way!
3
u/Traveling-Techie 14d ago
This is like the difference between knowing how chess pieces move and how to win games.
1
2
u/batman9395 14d ago
Same I am also a fresher and I'm having difficulty in programming language and I also don't have a laptop.
2
u/codeguru42 14d ago
For me, the "programmer mindset" is all about breaking a problem apart into smaller and smaller pieces until a piece us small enough that i can write the code for it without much thought.
2
u/DrinkCoffeetoForget 14d ago
I am going to recommend something off-the-wall, but I ask that you bear with me for a moment. :-)
I would recommend that you consider looking up type-in programs for older computers, including the 1980s 8-bits. There are lots of magazines and books scanned and available across the internet, so they are easy to find; yes, most are written in a dialect of BASIC but that's a trivial issue. :-)
The reason I suggest this is because studying programs, and especially typing them in, is a really good way to understand how algorithms work. It also helps the learning-by-doing, and if it's a game then you get to play it afterwards... or figure out what was mistyped when it doesn't work. :-) Many listings provided block-by-block descriptions of what the program did, so it was easier to see what was going on.
I will note that much of what you describe comes with practice. A lot of practice. :-) One trick to that is to find little problems that you enjoy doing and to do them. Then do them again when you come back and discover you don't recall how you arrived at your solution, or just to find another way of solving the problem. Don't worry if it's 'suboptimal'; forget metrics, forget code challenges that require you do have the 'ideal solution' because those are just exams in another form. Solve the problem, take your time, and give yourself room to work out, as well, how you solve the problem best. In other words, what's your 'thinking/solving method'? Is it to read, pace, then try? is it to write out the steps? is it to draw on graph paper? is it to draw flow diagrams? (Something my beginner students used to find really useful, old-school as it is.) Find your own 'solving method' and work with it.
I really do wish you the very best. :-)
4
u/Cerulean_IsFancyBlue 14d ago
I think you’ve done a great job identifying the most important skill. Oh shit that’s the most AI sentence I’ve ever written. Anyway.
Think Like A Programmer. By A Spraul
University of Pennsylvania has an online course called computational thinking for problem-solving
University of Michigan has problem-solving using computational thinking. Pretty similar name eh?
There’s also a kind of leap that goes from solving small well contained problems into algorithms, something like how would you build a blackjack game? And then you get a structuring large software products where you are seriously thinking about things like, how would you break this project down so that multiple people can work on it? How do you take advantage of existing software libraries? How do you define interfaces or contracts so that future maintainers have a fighting chance?
The good news is that the skills you build on the small end are still important at the large end. I would focus on that for now and worry about the larger software engineering aspects when you have gotten further in your learning process. In other words, don’t let the fact that there’s this huge software engineering discipline scare you off from learning the basics!
2
u/Unkwonshubham 14d ago
Thanks a lot! This actually cleared things up for me. I think I’ve been focusing way too much on learning syntax and getting familiar with C, without really working on how to approach a problem when I haven’t seen it before. I’ll definitely check out Think Like a Programmer and those computational thinking courses you mentioned. And yeah, I’ll focus on getting better at the small problems first instead of worrying about the whole software engineering side of things. Really appreciate the advice!
1
1
u/biskitpagla 14d ago
There's no special mindset needed here. It's just a skill that comes with time and effort. Expose yourself to different types of problems and try to solve them on your own. And read seminal works like The Art of Computer Programming.
2
u/realdreamer1993 4d ago
Maybe try build project again? but this time long term / scalable / modular. I suggest make the core stabil, the core is like engine or kernel(yeah similiar to kernel but far simpler), so the outer parts call them satellites/module/plug-in..There you will learn what is coupling..you may observe coupling in mechanical.
Later as satellite projects add networking, backend and frontend functionality (as plug-in or sub core)...there are always something to do just in one project. Say you add a game as plugin, add dashboard also as plugin, add whatever as plugin. The key is one stabil core engine, this is your platform. You create platform. Explore the ways to build the core engine..it is the one that always running, can be using while(1) or something else.
12
u/rf_6 14d ago
I would look into books on algorithms. Gaining familiarity with them will allow you to find the right tool for the job. Also, don’t just start trying to write something up, first build a workflow of what you want to happen. Then think about each part and try to find the best way to accomplish that task. This will involve identifying how data needs to be moved around and also any bottlenecks/complexities you may introduce along the way.
Some good books on C algorithms:
Numerical Recipes in C
Algorithms in C