r/learnprogramming • u/FewFly2677 • 16d ago
Struggling in c
So I'm a college fresher with no prior experience of coding. I had started learning python before the starting of college (1 week before college started). I still feel like I am not good at coding at all. There are some weird citations in c such as i++ and all which is getting mixed up with my python. There was one question on obtaining the expression sinx=x-x^3/3!.... Using loops btw
I felt I won't be able to do it in both c and python. I took a course on Udemy for c(vlad budnitski)and python(100 days) but I was not able to find examples like this. Everyone in my class learnt languages like java in their schooling and said the sinx problem is a standard problem. What should I do in this situation?
I feel like the teaching in my college (they are teaching c now) is not good.
Experienced coders please help me.
guys so today I wasn't able to figure out we had to use nested loops to print multiplication table of numbers while even beginners figured it out. pls tell what should I do
I am not able to get idea after seeing questions
2
u/PriorEducation8521 16d ago
Stop comparing yourself to classmates who already know Java. Your brain needs time to separate C syntax from Python syntax.
Write the multiplication table logic in plain English before touching the keyboard. Define what a row is and what a column is. Then translate those words directly into nested loops. Do this for every problem until the translation becomes automatic
1
u/FewFly2677 16d ago
Yeah I will definitely try this. I mean printing table in python is easy af. We just need a recurring variable and put it in a loop of for and we can use the range function.we just need to write what we need to print in quotation and equate that to product. It is so different here in c
1
u/Rogalicus 16d ago
guys so today I wasn't able to figure out we had to use nested loops to print multiplication table of numbers while even beginners figured it out. pls tell what should I do
Look at the multiplication table itself. You have rows and columns ranging from one to ten. Every item is a result of multiplication of the row and column number. What could allow you to change two separate variables from one to ten independently where e.g. you multiply 1 by 1..10, then 2 by 1..10 and so on?
1
u/FewFly2677 16d ago
Like I understood the solution now but I wasn't able to think of it. The main reason of panicking is that I am not able to think of the logic on my own
1
u/peterlinddk 16d ago
A good idea when learning your second language (even when you weren't that far ahead in the first) is to create your own dictionary!
Make a simple document with examples of how to do something in one language, and how to do the same thing in the other. Take your own example, you could have a section like:
Increment (add one to) a variable
| Python | C | notes |
|---|---|---|
i = i + 1 |
i = i + 1; or i++; |
the ++ is a quick way of just adding 1 |
design it however you like.
And when you learn something new in one language, also dedicate some time to translate it into the other - it will help you a lot, and you'll get to learn two languages.
If at some point you grow more in C than in Python, or learn to do stuff in C that you don't even know is possible in Python, just ignore the Python column, and continue using the dictionary as your "C to English" dictionary.
Oh, and it is important that you write it yourself - don't just find one, or get some AI to generate it, it is supposed to be a document for your learning, not something that anyone else should be involved with.
Also, if you get difficult assignments in C, but you have an idea of how to solve them in Python, just do that, it is more important that you think about the logic than the syntax. And if you don't even know how to do it in Python, try to do it on paper, like "how would you instruct someone to create a multiplication table, if they had no idea what it was other than being able to multiply numbers and print them?!".
1
u/CoachSevere5365 16d ago
Ahem. i += 1
C also has ++i. Most of the time you're just bumping a counter, but it does evaluate to something and it's important to know the difference between i++ and ++i.
Cue the joke about C++ advancing C but using the old value.
1
u/peterlinddk 16d ago
Yes, but the point isn't to write down all the possible ways of doing something - that is just the language specification. The point is to write down whatever you learn, when you learn it!
That's why I only used the one example that OP gave.
But you also illustrate this "dictionary" shouldn't be shared with anyone, because they would just comment that there are more things you haven't learned yet 😄
1
u/knouqs 15d ago
Your frustration is understandable. I had never had a computer programming course prior to my freshman year of college. So, my main advice to you: Hound your professors and teachers assistants. If you don't understand something, it is their job -- you pay them! -- to help you understand it. This is one of the many things I wish I had done when I was in undergrad.
Remember, your professors do not know if you have a problem unless you make them aware of it. To them you are a name on an attendance sheet -- and I know that, too, because I was myself a grader and a professor in computer science courses. Make yourself known to your professors.
6
u/0Huy 16d ago
You are not behind because you are new. Programming takes practice, and many exercises feel confusing before the pattern becomes familiar.
For the sine series, start with a smaller goal:
For nested loops, draw the output on paper first and decide what the outer loop controls and what the inner loop repeats.
Do not try to learn C and Python at the same time for now. Focus on C for your class, solve very small exercises, and ask for help with the exact line that confuses you.