assignment i can't solve

Light Poster
2Sep2007,08:03   #1
lakmi's Avatar
Hi i'm new to this place.. 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?
Light Poster
2Sep2007,08:26   #2
lakmi's Avatar
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 coderzone; 2Sep2007 at 10:40..
Light Poster
2Sep2007,10:32   #3
lakmi's Avatar
Hey can't anyone help? it works when the n value is three... but it gets stuck from there..
Team Leader
2Sep2007,10:41   #4
coderzone's Avatar
Why don't people understanbd that code should be in the code blocks.
Go4Expert Founder
2Sep2007,10:45   #5
shabbir's Avatar
Quote:
Originally Posted by coderzone
Why don't people understanbd that code should be in the code blocks.
Probably they don't want to help us.
Lakmi you can refer to thread help me to solve this problem
Light Poster
2Sep2007,20:37   #6
lakmi's Avatar
I'm sorry... i'm new here.. i didn't know that code blocks are used.. .. this is my first day on here
Go4Expert Founder
3Sep2007,09:02   #7
shabbir's Avatar
Quote:
Originally Posted by lakmi
I'm sorry... i'm new here.. i didn't know that code blocks are used.. .. this is my first day on here
Thats why the correction is done for you. Also I hope the link helped with your query.
Team Leader
3Sep2007,09:50   #8
jwshepherd's Avatar
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
Light Poster
3Sep2007,21:14   #9
lakmi's Avatar
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..
Go4Expert Member
5Sep2007,19:36   #10
arvind_khadri's Avatar
is the pattern correct???i cant find any similarity in it....