0% found this document useful (0 votes)
7 views6 pages

WCTB 2 (R)

This document contains the code submissions of a group (Group 18) for 10 questions. It includes R code for functions to evaluate quadratic equations, calculate exponents, find greatest common divisor, reverse a number, calculate digit sum, calculate circle area, create and manipulate data frames with student and sales data, and create plots for sales and placement data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

WCTB 2 (R)

This document contains the code submissions of a group (Group 18) for 10 questions. It includes R code for functions to evaluate quadratic equations, calculate exponents, find greatest common divisor, reverse a number, calculate digit sum, calculate circle area, create and manipulate data frames with student and sales data, and create plots for sales and placement data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

GROUP-18

Submitted by:

Riyashree Kukreja MBA22061


Siddhant Chauhan MBA22078
Mahima Prajapat MBA22042
Chirag Dash MBA22022
Surbhi Kumari MBA22085

#Question-1

Eval_Quadratic_Equa <- function (a,b,c){

d <- (b^2)-(4*a*c)

if(d<0){

return("The equation has no real roots")

else if (d>0){

root1 <- (-b + sqrt(d))/(2*a)

root2 <- (-b - sqrt(d))/(2*a)

return("The roots of the equation are", root1, "and", root2)

else {

root3 <- (-b)/(2*a)

return("The roots of the equation are", root3, "and", root3)

y<-Eval_Quadratic_Equa(4,5,6)

y<-Eval_Quadratic_Equa(1,3,2)
#Question-2

base<-as.numeric(readline(prompt='Enter base'))

exp<-as.integer(readline(prompt="Enter exponent"))

cal_exp <- function (base,exp){

if(exp>=0){

print(paste("The answer is", base^exp))

else {

print("Enter correct value")

cal_exp(3,2)

#Question-3

x<-as.integer(readline(prompt="Enter first number "))

y<-as.integer(readline(prompt="Enter second number "))

Calc_GCD_Recurr<-function(x,y){

if(x>y){

z=x

} else{

z=y

for(i in 1:z){

if((x%%i==0) && (y%%i==0)){

HCF=i

}
print(paste("The Greated common divisor of ", a, "and", b, "is= ",HCF))

Calc_GCD_Recurr(x,y)

#Question-4

x<-as.integer(readline("Enter the number you want to reverse "))

reverse_number<-function(x)

rev<-0

while(x>0)

n<-x%%10

rev<-rev*10+n

x=floor(x/10)

return(print(paste("Reverse of the number is= ", rev)))

reverse_number(x)

#Question-5

num<-as.numeric(readline(prompt="Enter a four digit number: "))

sum<-0

while(num>0){

sum = sum + (num%%10)

num = as.integer(num/10)

}
print(paste('The sum of digits is:', sum))

#Question-6

get_radius<-function(){

rad<-as.numeric(readline(prompt = "Enter the radius of circle "))

return(rad)

calc_area<-function(r){

area= (22/7)*r*r

return(area)

r=get_radius()

calc_area(r)

#Question-7

FName<-c("Tom", "Krish", "Nick", "Juli")

FName

LName<-c("Reacher", "Pete", "Wilson", "Williams")

LName

Age<-c(25,30,26,22)

Age

Data <- data.frame(FName,LName,Age)

Data

#Question-8
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)

StudentData <- data.frame(ID,Name,Gender,Age,Family_Income)

StudentData

#a

mean(StudentData$Family_Income)

median(StudentData$Family_Income)

max(StudentData$Family_Income)

min(StudentData$Family_Income)

sd(StudentData$Family_Income)

#b

mean(StudentData$Age)

median(StudentData$Age)

max(StudentData$Age)

min(StudentData$Age)

sd(StudentData$Age)

#c

cor(StudentData$Family_Income,StudentData$Age)

#Question-9
Month<-
c("January","February","March","April","May","June","July","August","September","October","Novemb
er","December")

Sales<-c(50,30,20,15,17,55,40,25,20,60,35,40)

salesData<-data.frame(Month,Sales)

salesData

plot(Month,Sales, type='l',col="blue", main="Sales per Month", xlab="Sales(million $)", ylab="Month")

barplot(Month, Sales,col="blue", main="Sales per Month", xlab="Sales(million $)", ylab="Month")

#Question-10

Industry<-c("IT","Sales and Marketing","Finance and Banking","Manufacturing","Others")

Placement<-c(55,88,39,24,63)

PlacementData<-data.frame(Industry,Placement)

PlacementData

pie(x=PlacementData$Placement, labels=PlacementData$Industry, main="Placement


Report",col=c("red", "blue",

"green", "cyan", "yellow"), radius = 1)

You might also like