Thread: Need some insight with these sets

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    2

    Post Need some insight with these sets

    How to write the function int SuperSum(int n); which finds the sum of Sum(1)+Sum(2)+...+Sum(n) (question #1). Use it to find the sum of (1)+(1+2)+...+(1+2+3+4+5+6+7+8+9+10)??

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    2
    Write a function int Sum(int n); which will find the sum 1+2+3+...+n. Use it to find the sum of 1+2+...+100

    How to write the function int SuperSum(int n); which finds the sum of Sum(1)+Sum(2)+...+Sum(n) (question #1). Use it to find the sum of (1)+(1+2)+...+(1+2+3+4+5+6+7+8+9+10)??

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    My guess is that you are expected to use a 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

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    So basically you're calculating the number of presents in the 12 days of Christmas...
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Isn't it the same as sum(n = 0, n =12) n * (12 - n) (in my fail math notation)
    Last edited by whiteflags; 12-20-2011 at 02:32 PM. Reason: yay, calculation error!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some insight on a few things
    By xxsomethingxx in forum C# Programming
    Replies: 0
    Last Post: 10-13-2009, 04:11 PM
  2. Noob needing some help and insight
    By punktilend in forum C++ Programming
    Replies: 1
    Last Post: 02-24-2009, 04:41 PM
  3. Seeking insight into a link Dave provided to someone
    By cdalten in forum C Programming
    Replies: 3
    Last Post: 03-25-2006, 11:13 AM
  4. ATD: C++ Sets
    By stalker in forum C++ Programming
    Replies: 9
    Last Post: 11-09-2004, 06:40 AM
  5. Insight Into const_cast on const data-members
    By shiv_tech_quest in forum C++ Programming
    Replies: 11
    Last Post: 01-21-2003, 05:53 AM