in reply to problem in my sub partition

Are you sure the values in your for loop in the sub are what you expect?

... for($i=1;$i<=$k;$i++){ print "i = $i, j= $j\n"; # Added to debug ...

I think you'll find the following does the trick:

for($i=1;$i<$k;$i++){

(Less than versus less than/equal to)

Replies are listed 'Best First'.
Re^2: problem in my sub partition
by GrandFather (Saint) on Nov 10, 2010 at 00:33 UTC

    or if you happen to be writing Perl rather than C you could:

    for my $i (1 .. $k - 1) {
    True laziness is hard work