0% found this document useful (0 votes)
9 views2 pages

R Programming Lab 1 1

The document contains R programming exercises that demonstrate user input handling and arithmetic operations using classes and objects. It includes a function to simulate rolling a dice and another function to determine if a given year is a leap year. The code snippets illustrate basic logical operations and user interaction through prompts.

Uploaded by

prajwalastronaut
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

R Programming Lab 1 1

The document contains R programming exercises that demonstrate user input handling and arithmetic operations using classes and objects. It includes a function to simulate rolling a dice and another function to determine if a given year is a leap year. The code snippets illustrate basic logical operations and user interaction through prompts.

Uploaded by

prajwalastronaut
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

R programming Lab: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()))

Q. To find the leap year:

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))

You might also like