Can anyone help me resolving below mentioned problem

#!/usr/bin/perl
@data=N;
\$sum=0;
print"enter the required No. of numbers to be inputed : f";
\$N=<STDIN>;
print"enter the number";
for(\$i=0;\$i<\$N;\$i+=1)
{\$data[\$i]=<STDIN>;
# chomp \$data[\$i];
\$sum=\$sum + \$data[\$i];}

# for(\$j=0;\$j=\$data[\$i];\$j+=1)
print"the entered numbers are",@data,"\n";
print"sum of the number:",\$sum,"\n";
print"Average value the numbers:",\$sum/\$N,"\n";

@sorting=sort(@data);
\$lengt=@data;
for (\$j=0;\$j < \$lengt;\$j++)
{# print \$sorting[\$j],"\n";
}

\$X= (@sorting[(\$j-1)/2]+ @sorting[\$j/2])/2;
print"the median is :\$X";

Q:the median is the middle value if the numbers have been sorted in
ascending order (for even numbers of values it is your choice to pick
the first or second of the middle numbers

2
Contributors
1
2
Views
10 Years
Discussion Span

is this school work? If you are entering integers sort() will not work properly. That is a lexical sort in ASCII order, not numeric order. To properly sort numbers use: <=>

@sorted = sort {\$a <=> \$b} @unsorted;

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.