Thread: The exercises in K&R, did you get them all?

  1. #1
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877

    The exercises in K&R, did you get them all?

    I was wondering of all who read the book "The C Programming Language", did you manage to get all of the exercises completed your first time through? Which were the ones that gave you the most trouble? Did you have any experience beforehand?

    I ask because the book is my starting point, and trying some of them I had to postpone after several tries, not being able to find the angle to complete it.

    There was one heinous exercise to make a vertical histogram that displays the number of words that I've planned out and failed at like 4-5 times. Is this normal or am I just a moron?

    Thanks.

  2. #2
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    K&R isnt' really a book to teach you about programming; it's a book to teach you C. There are some great exercises in it so I do recommend persisting, but maybe you need another book to complement K&R and fill in gaps that the authors assume you know.

  3. #3
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    @ Hodor, I think I see what you are saying, k&r is like a dictionary, not a language course. I started reading it before anything else, and it compliments a lot of online tutorials that explain things like arrays, functions, pointers, ect without very specific examples. It is like being able to hear the language in short bursts, while still having a translation dictionary to fall back on for more specifics.


    I was more wondering if there is ever a time when someone could look a problem in c that they hadn't seen before and intuit the solution using previous knowledge, or is there always trial and error?

  4. #4
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by Alpo View Post
    I was more wondering if there is ever a time when someone could look a problem in c that they hadn't seen before and intuit the solution using previous knowledge, or is there always trial and error?
    There isn't always trial and error... but getting to that point won't happen overnight, it requires practice.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Hodor View Post
    There isn't always trial and error... but getting to that point won't happen overnight, it requires practice.
    I disagree on practice helping; I do think experience helps.
    The problem with practice is too often you end up practicing making mistakes.

    If you have no one already experienced reviewing your practice it could all be a waste of time.

    Instead of doing a single problem/exercise over and over (which is the normal meaning of practice), I suggest looking at many different problems.
    And, looking for ways to apply past solutions (with improvements) to solve the new and different problems.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  6. #6
    Registered User
    Join Date
    Jan 2014
    Posts
    45
    Assuming that you're referring to exercises 1-13 and 1-14, you should note that the vertical histogram is presented only for those who want an extra challenge (with the 'standard' being the horizontal histogram). This is comparable to exercises 1-20 to 1-24, which are more advanced than the previous exercises in the chapter.

    I would see no problem in progressing onward to chapter 2 without having completed all of the advanced exercises. Though I would recommend, at a minimum, that you give at least one or two of those complicated exercises a fair shot.

    Read the reference carefully and focus primarily on the fundamental exercises and you'll do fine.
    Last edited by zyxwvuts; 04-11-2014 at 07:21 PM.

  7. #7
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by stahta01 View Post
    I disagree on practice helping; I do think experience helps.
    The problem with practice is too often you end up practicing making mistakes.

    If you have no one already experienced reviewing your practice it could all be a waste of time.

    Instead of doing a single problem/exercise over and over (which is the normal meaning of practice), I suggest looking at many different problems.
    And, looking for ways to apply past solutions (with improvements) to solve the new and different problems.

    Tim S.
    I actually meant practice on a wide range of exercises and problems, not the same problem over and over; I.e. I meant practice problem solving and programming in general. Sorry for the confusion.

  8. #8
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Quote Originally Posted by Alpo View Post
    I ask because the book is my starting point, and trying some of them I had to postpone after several tries, not being able to find the angle to complete it.
    Don't get stuck on one exercise, move on and revisit them if you have time so you don't lose pace. Also, you don't have to do every exercise. Think about books that you've used to learn calculus. Did you really do every problem of every chapter to learn how to solve those problems?

    In any case K&R exercises have a variety of solutions that can be found online, but obviously giving a particular exercise your own thorough try beforehand is the best way.

  9. #9
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    @xyxwvuts- That is the one I'm talking about. I actually think I'm close to solving it, I can get it to print vertically by switching xy axis of 2d array when printing, and limiting it to print only 1 row per column, but it is upside down and suffering some other problems as well.

    @Stahta- That's why I like these forums, because before I started coming here I had no idea the number of ways you could do a particular thing lol.

    Edit: Just fixed the upside down problem. I'll come back to the other problems it has later, thanks everyone for the advice.
    Last edited by Alpo; 04-12-2014 at 01:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. exercises
    By Kuro Tensai in forum C++ Programming
    Replies: 9
    Last Post: 04-24-2013, 08:34 PM
  2. C++ Exercises
    By GReaper in forum C++ Programming
    Replies: 11
    Last Post: 07-17-2010, 01:22 PM
  3. exercises in c++
    By BEN10 in forum C++ Programming
    Replies: 2
    Last Post: 07-26-2008, 04:07 AM
  4. C# Exercises
    By Rainbowinblack in forum C# Programming
    Replies: 0
    Last Post: 01-17-2008, 01:47 PM
  5. Exercises
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 10-14-2001, 11:29 AM

Tags for this Thread