Hi Friends,
Can anyone pls help me to resolve my school test in PERL................
as follows..... - #!/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";
QUE: 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.
6 1464
The way you have used sort function:
works for sorting strings in ascending order, numbers will be sorted according to ASCII value. If you want to sort the list numerically, use: -
@sorting=sort {$a<=>$b} @data; # ascending order
-
@sorting=sort {$b<=>$a} @data; # descending order
-
You can find median as follows: -
@sorting=sort {$a<=>$b} @data;
-
$length=@data;
-
if(($length%2)==0) { ###check for even no. of elements
-
$X1=$sorting[$length/2-1]; ##remember:length of array=last index+1
-
$X2=$sorting[$length/2];
-
print"the medians are :$X1 , $X2"; ##display 2 medians
-
}
-
else {
-
$X= $sorting[($length-1)/2];
-
print"the median is :$X"; # median incase of odd elements
-
}
-
-
Please do not help people with their school tests nithinpes.
Please do not help people with their school tests nithinpes.
I apologize for that. Since, some effort in scripting was done by the person, I thought it won't be against posting guidelines.
Anyway, this won't be repeated.
I apologize for that. Since, some effort in scripting was done by the person, I thought it won't be against posting guidelines.
Anyway, this won't be repeated.
Homework I can see, but not tests. They have also posted this question on another forum so I think they are cheating, we should not encourage that, IMHO.
Kevin
nithinpes,
please check your PM's
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Howard Nease |
last post by:
Hello, everyone. I would appreciate any advice that someone could give me on
my future career path. Here is my situation:
I am a bright Junior in a very well-respected private high school, taking...
|
by: Kevin Parkes |
last post by:
Because Active State haven't yet built the additional modules I will
require I'm trying to build Perl 5.8.0 from source using dmake and the
Borland C++ command line compiler from the cmd.exe...
|
by: Andrea M. Segovia |
last post by:
I just compiled (but did not install) perl 5.8.0 on an SGI Origin 300
server (IP35) running IRIX 6.5.20m.
Make test reported one test error, which I narrowed down to
.../lib/ExUtils/t/Constant.t...
|
by: Jussi Mononen |
last post by:
Hi,
I'm having problems to successfully execute the test scripts on a
Compaq host ( OSF1 tr51bdev V5.1 2650 alpha ). Almost all tests end up
with the following error message
"PARI: *** ...
|
by: Fred |
last post by:
I'm trying to build perl 5.8.6 on an HP-UX 11.11 box.
I can create the Makefile OK, and make doesn't return
any errors. However, when I run make test I receive
the error below regarding the...
|
by: Rare Book School |
last post by:
RARE BOOK SCHOOL (RBS) is pleased to announce its Spring and Summer
Sessions 2004, a collection of five-day, non-credit courses on topics
concerning rare books, manuscripts, the history of books...
|
by: DrUg13 |
last post by:
In java, this seems so easy. You need a new object
Object test = new Object() gives me exactly what I want.
could someone please help me understand the different ways to do the
same thing in...
|
by: pratchaya |
last post by:
This is my sample error in my MySQL Log
New value of fp=(nil) failed sanity check, terminating stack trace!
Please read http://www.mysql.com/doc/en/Using_stack_trace.html and
follow instructions...
|
by: genestarwing |
last post by:
QUESTION:
Write a program that opens and read a text file and records how many
times each word occurs in the file. Use a binary search tree modified
to store both a word and the number of times it...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |