B)Implement R script to read person_s age from keyboard and display whether he is
eligible for voting or not?
PROGRAM :
{
age <- as.integer(readline(prompt = "Enter your age :"))
if (age >= 18) {
print(paste("You are valid for voting :", age))
} else
{
print(paste("You are not valid for voting :", age))
}
}
Output:
Enter your age:17
You are not valid for voting:17
Enter your age:19
You are valid for voting
C) Implement R script to find biggest number between two numbers.
{
x <- as.integer(readline(prompt = "Enter first number :"))
y <- as.integer(readline(prompt = "Enter second number :"))
if (x > y) {
print(paste("Greatest is :", x))
}
else {
print(paste("Greatest is :", y))
}
}
Output:
Enter first number:12
Enter second number:16
[1]"Greatest is: 16"
D) Implement R script to check the given year is leap year or not.
{
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:
Enter a year:2022
[1]"2022 ia not a leap year"