0
9.3kviews
Write a R program to check the leap year or not.
1 Answer
0
1.1kviews

Explanation:-

  • Take year as a input from the user and store it in a variable y.
  • Check if divisible by 4 but not 100, DISPLAY "leap year"
  • Check if the year is divisible by 400, DISPLAY "leap year"
  • Otherwise, DISPLAY "not leap year"

Code:-

y = as.numeric(readline(prompt = 'year'))
if ((y %% 4) == 0){
  if ((y %% 100) == 0){
    if ((y%% 400) ==0){
      print(paste(y,'is a leap year'))
    }
    else {
      print(paste(y,"is not a leap year"))
    }
  }
  else{
    print(paste(y,"is a leap year"))
  }
}else{
  print(paste(y,"is not a leap year"))
}

Output:-

enter image description here

Please log in to add an answer.