Leap year or not in R Programming Language

Leap year or not in R Programming Language

year = as.integer(readline(prompt=”Enter a year: “))
if((year %% 4) == 0) {
if((year %% 100) == 0) {
if((year %% 400) == 0) {
print(paste(year,”is a leap year”))
} else {
print(paste(year,”is not a leap year”))
}
} else {
print(paste(year,”is a leap year”))
}
} else {
print(paste(year,”is not a leap year”))
}
Output 1:
Enter a year: 2021
[1] “2021 is not a leap year”

Output 2:
Enter a year: 2024
[1] “2024 is a leap year”

No Comments

Post a Reply