Thread: C basic examples

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    C basic examples

    hi everyone, it's been 3 years past, and i decided teaching C to my lower class men. BASIC C.

    i've posted some codes in C in my blog:

    C tutorials.

    i will be posting more soon, and i hope these would help any Computer Science, Info Tech, Management Info Sys student out there who have trouble in C - the by far most basic syntax.

    - Ogs

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    I'm not sure if it's just a browser issue, but this is how your code looks to me:
    Code:
    #include
    #include
    
    
    quadratic(double x, double y, double z)
    {
    double first, second;
    first = (-y+sqrt((y*y)-4*x*z))/(2*x);
    second = (-y-sqrt((y*y)-4*x*z))/(2*x);
    printf( "%f %f\n", first, second );
    getche();
    return 0;
    }
    
    main()
    {
    double a, b, c;
    
    while( 1 ) //this while loop states that this loop would always run while the operation is true.
    {
    printf("Input value a:\n");
    scanf( "%f", &a );
    if(a>0) printf("input values b and c");
    scanf( "\n%f", &b );
    scanf( "\n%f", &c );
    
    quadratic( a, b, c );
    }
    }
    Obviously that code appears to be missing several things. It may just be a display issue though.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    3
    Quote Originally Posted by bithub View Post
    I'm not sure if it's just a browser issue, but this is how your code looks to me:
    Code:
    #include
    #include
    
    
    quadratic(double x, double y, double z)
    {
    double first, second;
    first = (-y+sqrt((y*y)-4*x*z))/(2*x);
    second = (-y-sqrt((y*y)-4*x*z))/(2*x);
    printf( "%f %f\n", first, second );
    getche();
    return 0;
    }
    
    main()
    {
    double a, b, c;
    
    while( 1 ) //this while loop states that this loop would always run while the operation is true.
    {
    printf("Input value a:\n");
    scanf( "%f", &a );
    if(a>0) printf("input values b and c");
    scanf( "\n%f", &b );
    scanf( "\n%f", &c );
    
    quadratic( a, b, c );
    }
    }
    Obviously that code appears to be missing several things. It may just be a display issue though.
    oh boy, thanks for pointing that out.. w8 a sec while i'll fix it

    - Ogs

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    3
    fixed it! sorry about the inconvenience earlier. apparently the page made the stdio.h an html tag.. anyway.. i will be posting more soon..

    thank you

    - Ogs

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Just what we needed. More flawed C tutorials on the web. As though there aren't enough already.

    I'm not even going to start to point out the flaws and problems, except for telling you none of your examples actually compile. I didn't look for bugs in the program and yet I found several by glancing over them.
    Please, don't continue with this. I don't know if it's just that you're not good enough of a coder or that you're too lazy to write proper tutorials, but you're teaching other people bad coding. If anybody would bother reading it because the "tutorials" are not much more than code snippets, which you can easily find anywhere on the web.

    Sorry for being so harsh, but there are enough places that teach you "Bad C"

  6. #6
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by ogs-peace View Post
    hi everyone, it's been 3 years past, and i decided teaching C to my lower class men. BASIC C.

    i've posted some codes in C in my blog:

    C tutorials.

    i will be posting more soon, and i hope these would help any Computer Science, Info Tech, Management Info Sys student out there who have trouble in C - the by far most basic syntax.

    - Ogs
    It's good to have a C-tutorial on your blog but I would suggest that you should put those things from C which are rarely seen anywhere, not just basics which anyone can find anywhere on the whole internet.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    getche() is a non-standard function. main() should always be of type int and return an int value.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by MK27 View Post
    getche() is a non-standard function. main() should always be of type int and return an int value.
    Exactly. I was talking of these things which people dont know(I too didn't know), you(the OP) should include in your blog.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  9. #9
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by MK27 View Post
    getche() is a non-standard function. main() should always be of type int and return an int value.
    That's just scratching the surface.
    bit∙hub [bit-huhb] n. A source and destination for information.

  10. #10
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    One thing I would say is very strange is that the OP circumvents stray stdin \n's with getche() and appropriate things in the scanf() template, but does not bother to explain why!

    Since 20-30% of beginner questions at cboard revolve around those stray \n, I would say this is an important issue for most beginning programmers. The material on the site would be fine for someone in their first week (hour?) or so of C programming, so you might as well explain things like that. In doing so, you should also make your own method consistent (rather than haphazard), and not rely on non-standard functions to do it.

    IMO, learning to use scanf() properly is fundamental but you appear to have just skipped any explanation of what you are actually doing when you have the opportunity to do so! In other words, the code you are using to demonstrate simple things like datatypes is more complex than what is being demonstrated.
    For example:
    Code:
    if ((year%100)==0)
    leapyear=((year%4)==0);
    else
    leapyear=((year%4)==0);
    I don't think this will be exactly transparent to a newbie (whom you claim to be instructing); in fact, it has a potentially counter-intuitive aspect, but you provide no explanation at all! If the reader can understand the conditions, then they already understand if-else, so it seems to me that this demo will not be useful to anyone at all.

    If you look at a good intro C book or tutorial, you will notice code is never introduced unless it is prefaced with enough material to make it comprehensible.

    So I would say the commentary is sketchy and inconsistent. You should focus on developing and explaining the examples you currently have before you start adding more.
    Last edited by MK27; 09-14-2009 at 10:15 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need a basic Linux web page designer (editor)
    By BobS0327 in forum Tech Board
    Replies: 5
    Last Post: 12-30-2006, 05:30 PM
  2. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 10:28 AM
  3. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  4. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 08:41 PM

Tags for this Thread