Jan 9, 2001 #1 thendal Programmer Joined Aug 23, 2000 Messages 284 Hi! How to find a given number is odd or even,any help is appriciated Thanks in advance
Jan 9, 2001 #2 goBoating Programmer Joined Feb 8, 2000 Messages 1,606 Location US Hello thendal, Divide by 2 and see if there is anything after the decimal with the 'modulus' operator, % #!perl $value = 4; $odd_num = $value % 2; if ($odd_num) { print "$value is odd\n"; } else { print "$value is even\n"; } $value = 5; $odd_num = $value % 2; if ($odd_num) { print "$value is odd\n"; } else { print "$value is even\n"; } 'hope this helps.... keep the rudder amid ship and beware the odd typo Upvote 0 Downvote
Hello thendal, Divide by 2 and see if there is anything after the decimal with the 'modulus' operator, % #!perl $value = 4; $odd_num = $value % 2; if ($odd_num) { print "$value is odd\n"; } else { print "$value is even\n"; } $value = 5; $odd_num = $value % 2; if ($odd_num) { print "$value is odd\n"; } else { print "$value is even\n"; } 'hope this helps.... keep the rudder amid ship and beware the odd typo
Jan 9, 2001 #3 tanderso IS-IT--Management Joined Aug 9, 2000 Messages 981 Location US You could compact that a bit: my $value = 4; if ($value%2) {print "$value is even";} else {print "$value is odd";} Sincerely, Tom Anderson CEO, Order amid Chaos, Inc. http://www.oac-design.com Upvote 0 Downvote
You could compact that a bit: my $value = 4; if ($value%2) {print "$value is even";} else {print "$value is odd";} Sincerely, Tom Anderson CEO, Order amid Chaos, Inc. http://www.oac-design.com
Jan 9, 2001 Thread starter #4 thendal Programmer Joined Aug 23, 2000 Messages 284 Thanks a lot goboating and tom anderson, with love to perl Thendal Upvote 0 Downvote