1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

assignment i can't solve

Discussion in 'C' started by lakmi, Sep 2, 2007.

  1. lakmi

    lakmi New Member

    Joined:
    Sep 2, 2007
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Hi i'm new to this place.. :eek: Great to be here..
    anyway, i'm having this problem with an assignment i have to complete.. it's regarding a prblem called non increasing partitions of n. i have to get the output
    4
    3 1
    2 2
    2 1 1
    1 1 1 1
    when given the input 4.. i already have an algorithm i tried out, but the only answer it gives in the end is 4.. i believe this is a recursive algorithm.. does anyone have any idea?
     
  2. lakmi

    lakmi New Member

    Joined:
    Sep 2, 2007
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    I just came up with this code.. but it doesnt work from the 3rd line onwards.. :-(
    Code:
    #include<stdio.h>
    void partition(int no);
    int main()
    {
       int n=4;
    
       partition(n);
    
    }
    
    void partition(int no)
    {
       int j=0;
       int i;
       for(i=no; i>=1; i--)
       {
            printf(" %d , %d  \n", no-j, no-i);
            j++;
       }
    }
    ~
    ~
     
    Last edited by a moderator: Sep 2, 2007
  3. lakmi

    lakmi New Member

    Joined:
    Sep 2, 2007
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Hey can't anyone help? it works when the n value is three... but it gets stuck from there..
     
  4. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    734
    Likes Received:
    37
    Trophy Points:
    0
    Why don't people understanbd that code should be in the code blocks.
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    Probably they don't want to help us.
    Lakmi you can refer to thread help me to solve this problem
     
  6. lakmi

    lakmi New Member

    Joined:
    Sep 2, 2007
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    I'm sorry... i'm new here.. i didn't know that code blocks are used.. :(.. this is my first day on here
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    Thats why the correction is done for you. Also I hope the link helped with your query.
     
  8. jwshepherd

    jwshepherd New Member

    Joined:
    Aug 13, 2007
    Messages:
    135
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    VP Technology Corporation
    Location:
    Texas
    Home Page:
    you are increasing j to often try creating a for loop with j as well inside the I loop area.

    Also lthe length you have should be dynamic based on the length of N or you will never get 4 1's
     
  9. lakmi

    lakmi New Member

    Joined:
    Sep 2, 2007
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    yeah.. datz the problem i'm havin.. anyway, i created a program so as to get the N from the user.. anyways, it gives the following result when n = 4 now....

    4
    3 1
    2 2
    2 1 1
    1 1
    1 1

    It doesn't even like this for any values beyond 4.. hmmmm
    Anyway, it's in a presentable form now atleast for the assignment purposes..
    lol..
     
  10. arvind_khadri

    arvind_khadri New Member

    Joined:
    Sep 4, 2007
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    0
    is the pattern correct???i cant find any similarity in it....
     
  11. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    The pattern is next line you represent any number as the sum of 2 numbers in the above line. Or simple words break the numbers as you move down the line numbers.
     

Share This Page