Thread: Simple Function

  1. #1
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187

    Simple Function

    Hey guys,
    I'm doing some exercises for Algorithms Complexity and thing is I'm stuck.

    I can't find to understand what this is supposed to do :

    Code:
    s = sum(K=0 ... N-1) a[k]
    Any idea ?

    Thanks.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    25,638
    It looks like an attempt to render summation notation, i.e., sum of a[k] from k=0 to k=n-1. Translating it to C would likely involve a for loop.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    It it inside a while loop

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    25,638
    Ah well, it amounts to the same thing, though I still think that a for loop would be more idiomatic when converting from summation notation.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with simple function
    By alexl in forum C Programming
    Replies: 8
    Last Post: 12-23-2010, 10:46 AM
  2. simple function
    By barilla in forum C Programming
    Replies: 2
    Last Post: 02-08-2010, 12:09 PM
  3. Replies: 5
    Last Post: 10-17-2006, 08:54 AM
  4. Need help with simple c++ function
    By Ricochet in forum C++ Programming
    Replies: 7
    Last Post: 11-13-2003, 11:46 AM
  5. Simple Function but......I NEED HELP
    By justin69enoch in forum C Programming
    Replies: 7
    Last Post: 09-29-2002, 09:56 PM