473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Can anyone pls help me to resolve my school test in PERL

Hi Friends,

Can anyone pls help me to resolve my school test in PERL................

as follows.....

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. @data=N;
  3. $sum=0;
  4. print"enter the required No. of numbers to be inputed : f";
  5. $N=<STDIN>;
  6. print"enter the number";
  7. for($i=0;$i<$N;$i+=1)
  8. {$data[$i]=<STDIN>;
  9. # chomp $data[$i];
  10. $sum=$sum + $data[$i];}
  11.  
  12. # for($j=0;$j=$data[$i];$j+=1)
  13. print"the entered numbers are",@data,"\n";
  14. print"sum of the number:",$sum,"\n";
  15. print"Average value the numbers:",$sum/$N,"\n";
  16.  
  17. @sorting=sort(@data);
  18. $lengt=@data;
  19. for ($j=0;$j < $lengt;$j++)
  20. {# print $sorting[$j],"\n";
  21. }
  22.  
  23. $X= (@sorting[($j-1)/2]+ @sorting[$j/2])/2;
  24. 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.
Feb 12 '08 #1
6 1464
nithinpes
410 Expert 256MB
The way you have used sort function:

Expand|Select|Wrap|Line Numbers
  1. @sorting=sort(@data);
  2.  
works for sorting strings in ascending order, numbers will be sorted according to ASCII value. If you want to sort the list numerically, use:

Expand|Select|Wrap|Line Numbers
  1. @sorting=sort {$a<=>$b} @data; # ascending order
  2. @sorting=sort {$b<=>$a} @data; # descending order
  3.  
Feb 12 '08 #2
nithinpes
410 Expert 256MB
You can find median as follows:

Expand|Select|Wrap|Line Numbers
  1. @sorting=sort {$a<=>$b} @data;
  2. $length=@data;
  3. if(($length%2)==0) {   ###check for even no. of elements
  4.   $X1=$sorting[$length/2-1];     ##remember:length of array=last index+1
  5.   $X2=$sorting[$length/2];
  6.   print"the medians are :$X1 , $X2";      ##display 2 medians
  7. }   
  8. else {
  9. $X= $sorting[($length-1)/2];
  10. print"the median is :$X";         # median incase of odd elements
  11. }
  12.  
  13.  
Feb 12 '08 #3
KevinADC
4,059 Expert 2GB
Please do not help people with their school tests nithinpes.
Feb 12 '08 #4
nithinpes
410 Expert 256MB
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.
Feb 12 '08 #5
KevinADC
4,059 Expert 2GB
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
Feb 12 '08 #6
numberwhun
3,509 Expert Mod 2GB
nithinpes,

please check your PM's
Feb 12 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

75
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...
0
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...
0
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...
0
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: *** ...
0
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...
0
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...
11
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...
2
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...
66
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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
1
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...
0
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.