Last active
December 14, 2015 10:18
-
-
Save Ezveus/5070677 to your computer and use it in GitHub Desktop.
Programme à la con qui dit si l'année est bissextile. En PHP et en Ruby. PS : Il semble que PHP ne gère pas très bien les grands nombres.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
function isItLeapYear($year) { | |
if ($year % 400 == 0) | |
return true; | |
elseif ($year % 4 == 0) { | |
if ($year % 100 == 0) | |
return false; | |
else | |
return true; | |
} | |
else | |
return false; | |
} | |
echo "Enter a year : "; | |
fscanf(STDIN, "%d\n", $year); | |
$isLeapYear = isItLeapYear($year); | |
if ($isLeapYear) | |
echo $year . " is a leap year\n"; | |
else | |
echo $year . " isn't a leap year\n"; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def isLeapYear? year = 0 | |
if year % 400 == 0 | |
true | |
elsif year % 4 == 0 | |
if year % 100 == 0 | |
false | |
else | |
true | |
end | |
else | |
false | |
end | |
end | |
printf "Enter a year : " | |
year = $stdin.readline.strip.to_i | |
isLeapYear = isLeapYear? year | |
puts "#{year} is a leap year" if isLeapYear | |
puts "#{year} isn't a leap year" unless isLeapYear |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Output Ruby : | |
Enter a year : 4564894532165189416891189189198198189181981189489487846454564545648948979465418944132 | |
4564894532165189416891189189198198189181981189489487846454564545648948979465418944132 is a leap year | |
Output PHP : | |
Enter a year : 4564894532165189416891189189198198189181981189489487846454564545648948979465418944132 | |
9223372036854775807 isn't a leap year |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment