hey guys ,
I am supposed to write a recursive function which find the partition of a number n ,, for example if n=3 , it should print 1 1 1 , 1 2 , 3
I wrote the program but i am getting the two partition 1 2 and 2 1 which are the same ,, how can i avoid that ?
this is the code :
1 2 3 4 5 6 7 8 9 10 11 12
void PrintPartition( int n , int A[] , int j )
{
if( n<=0 ) {
printArray( A, j );
return ;
}
for( int i=1 ; i<=n ; i++ )
{
A[j]=i;
PrintPartition( n-i , A ,j+1 );
}
}
the first call of the function is : PrintPartition( n , A , 0 ) ;
Please help mee I have a quiz after 3 hours ..
Thanks in advance :)