R Programming Lab 1 1
R Programming Lab 1 1
Q.1 R program to accept user input and perform arithmetic and logical
operations using classes and objects.
user_integer=as.integer(readline(prompt="Enter an integer"))
print(paste("the entered integer is:",user_integer))
print(paste("The entered string is:",user_string))
#Arithmetic Operations:
num1<- as.integer(readline(prompt="Enter the first number"))
add<- num1+num2
diff<-num1-num2
product<-num1*num2
quotient<-num1/num2
remainder<-num1%%num2
print(paste("sum is:",add))
print(paste("difference is:",diff))
print(paste("product is:",product))
print(paste("remainder is:",remainder))
print(paste("quotient is:",quotient))
#Logical Operations
a<-TRUE
b<-FALSE
print(paste("a AND b:",a && b))
print(paste("a OR b", a || b))
print(paste("NOT a:", !a))
R programming Lab:3
Q.Make a dice
rolladice<- function() {
return (sample(1:6,2))
}
print(paste("you rolled:",rolladice()))
leap_year<- function(year){
if ((year %% 400 == 0) || (year %% 4 == 0 && year %%100!= 0 )) {
return(paste(year,"is a leap year"))
} else {return(paste(year,"is a not leap year"))}
}
year_input<- as.integer(readline(prompt =" Enter the year:"))
print(leap_year(year_input))