Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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?

Enoch was right!
Enjoy the last years of Rome.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2016-10-26 09:27 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (338 votes). Check out past polls.