Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: New student, can we write this program in perl...

by Jenda (Abbot)
on Oct 22, 2012 at 23:23 UTC ( #1000426=note: print w/ replies, xml ) Need Help??


in reply to Re^2: New student, can we write this program in perl...
in thread New student, can we write this program in perl...

use strict; # #include<conio.h> #void main() #{ my (@a,@b,@c,$i,$j,$k,$n); print("Enter the number of elements\n"); $n = <>; printf("Enter %d numbers\n",$n); for($i=0;$i<$n;$i++) { push @a, scalar(<>); } for($i=0;$i<$n;$i++) { if(($a[$i]%2)==0) { $b[$j]=$a[$i]; $j++; } else { $c[$k]=$a[$i]; $k++; } } print("The even numbers are\n"); for($i=0;$i<$j;$i++) { printf("%d\n",$b[$i]); } printf("The odd numbers are\n"); for($i=0;$i<$k;$i++) { printf("%d\n",$c[$i]); } <>; #}

Not that this was the best (or even just a particularly good) way to write this, but it's the minimal change. Huge difference from the C code, right?

Jenda
Enoch was right!
Enjoy the last years of Rome.


Comment on Re^3: New student, can we write this program in perl...
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000426]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2015-07-30 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls