Professional Documents
Culture Documents
Group1 Assignment2
Group1 Assignment2
Group 1
Eval_Quadratic_Equa<-function(a, b, c, x){
equation<-a*x*x+b*x+c
return(equation)
}
l<-as.numeric(readline("Enter coefficient of x square: "))
m<-as.numeric(readline("Enter coefficient of x: "))
n<-as.numeric(readline("Enter the constant of equation: "))
o<-as.numeric(readline("Enter the value of x: "))
value<-Eval_Quadratic_Equa(l,m,n,o)
print(paste("The value of equation will be",value))
2. Write a function calc_exp(base, exp) which computes the exponent of any number,
i.e., baseexp. The function should take two values as base, which can be float or
integer. Exp will be an integer greater than 0
calc_exp<-function(base, exp){
number<-base^exp
return(number)
}
b<-as.numeric(readline("Enter the base number: "))
e<-as.integer(readline("Enter the exponent: "))
baseexp<-calc_exp(b,e)
print(paste("The value of base raised to the given exponent will be",baseexp))
Calc_GCD_Recurr<-function(a, b){
if(a>b) {
for (i in b:1) {
if(a%%i==0 & b%%i==0) return(i) else if(a%%b==0) return(i)
i=i-1
WCTB Group Assignment 2
Group 1
}
}
if(b>a) {
for (i in a:1) {
if(a%%i==0 & b%%i==0) return(i) else if(b%%a==0) return(i)
i=i-1
}
}
}
x<-as.integer(readline("Enter the first positive integer: "))
y<-as.integer(readline("Enter the second positive integer distinct from first: "))
gcd<-Calc_GCD_Recurr(x,y)
print(paste("GCD of given two distinct positive intergers is",gcd))
reverse_number<-function(x){
temp<-0
while (x>0) {
dig<-x%%10
temp<-temp*10+dig
x<-x%/%10
}
return(temp)
}
n <- as.numeric(readline("Enter the number you want to be reversed: "))
rev<-reverse_number(n)
print(paste("The reversed number will be",rev))
5. A four-digit integer is entered through the keyword. Write a function to calculate the
sum of the four-digit number
temp<-0
for (i in 1:4) {
temp=temp+(num4%%10)
num4=as.integer(num4/10)
i=i+1
}
a) Define the function named get_radius() which returns the radius of the circle
b) Define the function named calc_area() which returns the area of circle
get_radius<-function(){
x<-as.numeric(readline("Enter the radius of the circle in cms: "))
return(x)
}
calc_area<-function(y){
a<-3.14*y^2
return(a)
}
radius<-get_radius()
area<-calc_area(radius)
print(paste("The area of the circle will be",area,"cm square"))
FName<-c("Tom","Krish","Nick","Juli")
LName<-c("Reacher","Pete","Wilson","Williams")
Age<-c(25,30,26,22)
people<-data.frame(FName,LName,Age)
row.names(people)<-c("0","1","2","3")
people
8. Create the given student data frame and do the required exercise
a) Calculate mean, median, maximum, minimum, and standard deviation of salary
b) Calculate mean, median, maximum, minimum, and standard deviation of age
c) Is there any correlation between age and salary?
ID<-
c("MBA21001","MBA21002","MBA21003","MBA21004","MBA21005","MBA21006")
Name<-c("Rohit","Meenal","Sneha","Mrigank","Naresh","Deepika")
Gender<-c("Male","Female","Female","Male","Male","Female")
Age<-c(24,25,22,23,25,23)
Family_Income<-c(120000,98000,112000,85000,92000,106000)
students<-data.frame(ID,Name,Gender,Age,Family_Income)
students
summary(students[5])
sd(students[,5])
summary(students[4])
sd(students[,4])
WCTB Group Assignment 2
Group 1
cor(students[4],students[5])
Month<-c("January","February","March","April","May","June","July",
"August","September","October","November","December")
Sales<-c(50,30,20,15,17,55,40,25,20,60,35,40)
10. Draw a pie chart to visualize the placement statistics on given placement data