Thread: assignment help

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    1

    assignment help

    hi, i need great assistance in one of my assignments for school.

    you've probably encountered this problem once or twice in your life.

    All i need help on is to start it off and a push in the general idea, frankly, i'm totally lost on how to do this problem (still new to this stuff).

    Given the sum "K" which is an integer and positive number, show all possible 3 number combinations that add up to K.

    The three numbers are all not equal to 0. and num1 <= num2 <= num3

    for example:

    given number "5"
    combinations include:
    1+1+3
    1+2+2

    Thanks a bunch for your time!

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    45

    reply

    You have to look in some other place rather than posting here. You have to do the assignments by yourself

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    32
    You didn't actually specify that the individual numbers have to be positive hence there could be an infinite number of solutions:

    eg. Given a single valid solution:
    K = p + q + r, then it holds that,
    = (p - 1) + q + (r + 1)
    = (p - 2) + q + (r + 2)
    = ...

    :P (Sorry, I'm about to go to bed...)
    Beware the fury of a patient man.

  4. #4
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    What they are trying to say is "write some code you think will work and when it doesn't post it here for help."
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  5. #5
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    Code:
    #include <stdio.h>
    #define STR "Solution #%d: %d+%d+%d=%d\n"
    int main()
    {int K=59;
    int j,k,h,
    c=0;for(j=
    0;j<K;j++)
    for(k=j;k<
    K;k++)for(
    h=k; h< K;
    h++){if (j
    <=k &&k<=h
    && (j+k+h)
    ==K)printf
    (STR,c++,j
    ,k,h,K); }
    return 0;}
    Please work for your homework, if you post some code, ill fix it.

    -LC
    Last edited by Lynux-Penguin; 10-04-2003 at 08:11 PM.
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 01:21 PM