Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by Jenda (Abbot)
on Oct 22, 2012 at 23:23 UTC ( [id://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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-26 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found