Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Could someone give me a basic lesson/project to do in C

  1. Dec 13, 2014 #1
    I know there are many resources online for this but I'd to learn from someone on here. Could you provide me a lesson/project to do and finish in C language for beginners. I can get the software needed to compile and such and will post an image when I am done or provide whatever proof of completion needed. I just need a beginner lesson to get my feet wet in C.

  2. jcsd
  3. Dec 13, 2014 #2


    User Avatar
    Gold Member

    https://projecteuler.net/ Has tons of great exercises for novice programmers. You can do some of these exercises and then ask questions about your code here. Just put your source on www.pastebin.com and post the link here.
  4. Dec 13, 2014 #3
    Please give a specific one to do. One you think would be good for a beginner C project.
  5. Dec 13, 2014 #4


    User Avatar
    Gold Member

  6. Dec 13, 2014 #5


    Staff: Mentor

    This might be too hard for someone who is just a beginner at C.

    Here's an easier one that I made up after looking at problem #1 in the Project Euler problems.

    Print all of the positive integers <= 200 that are multiples of 3 or 5. The first few numbers in the output should be 3, 5, 6, 9, 10, and so on.

    Let us know if that's too easy for you.
  7. Dec 13, 2014 #6
    I should point out that I am very new to this but want to learn more and more about C.

    And no that project is not easy for me.
    I was able to make the basic "hello world" program, when searching the web

    #include <stdio.h>
    int main()
    int num
    printf("hello world")
    return 0;

    So I was able to compile just fine.
    However, even that I don't fully understand what's going on to make it print out Hello World.
    Why #include <stdio.h> what is that? what does it mean?
    Why int main()?
    why the brackets
    why int num;?
    Print makes sense as it's the purpose of the program. but why f? and why return 0;
    Is that sort of like saying there is nothing more to do here.
    I think I understand the brackets as to mean Opening and Closing of a program/function/operation?

    Why does any of that exist and in that order?
    And could I have a hint for the program asked not sure how to go about it

  8. Dec 13, 2014 #7


    User Avatar
    Gold Member

    You are asking us to answer all of the basic questions about language syntax. You need to study this stuff on your own. LOOK UP what they each mean and do and then apply them in VERY simple cases to make sure you understand them, and then come back with questions that you still have.
  9. Dec 14, 2014 #8
    It will take an inordinate amount of time and effort to learn a programming language by "searching the web", especially if, as I suspect the case is here, it is your first programming language, when this will most likely simply fail. Get a book. Or find a tutorial on the web. Either way, stick with it and follow it methodically. Do not go for random examples.
  10. Dec 14, 2014 #9


    User Avatar

    This begs the question: why are you learning C in the first place? If you're learning out of personal interest and you're new to programming in general, you're probably better off starting with a more beginner-friendly language like Python. The "hello, world" program in Python is just one line long:

    Code (Python):
    print("hello, world")

    As phinds pointed out above, most of the questions you asked about this program would be fairly quickly answered if you read a good book or tutorial on C, which you should really be doing anyway if you want to learn C.

    There's just one exception that's worth mentioning to save you any future confusion: the "int num;" line in your example program is redundant. It declares an integer variable that the program never uses. The minimal "hello, world" program in C is just

    Code (C):
    #include <stdio.h>

    int main(void)
        puts("hello, world");
        return 0;
    Last edited: Dec 14, 2014
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook