R Question 1: for/while loop
#Answer of Q1 for loop
n<-1
for (x in 1:13) #from 1 to 13
{
n<-n*x
}
print(n)
## [1] 6227020800
#Answer of Q1 while loop
f <-1
i <-1
while (i<=12)
{
i<-i+1
f <-f*i
}
print (f)
## [1] 6227020800
R Question 2: numberic vector that contains the sequence from 10 to 50 by 5
#range from 5*2=10 and 5*10=50
x <-2:10
y <-5
x*y
## [1] 10 15 20 25 30 35 40 45 50
R Question 3: distance, slope and the y intercept of 2 points
lines <- function(x1,y1,x2,y2) {
yi <- y2-y1
xi <- x2-x1
slope <- (yi)/(xi)
distance <-sqrt(sum(((xi^2)+(yi^2))))
yint <- y1-((yi)/(xi))*x1
return (list (slope,distance,yint))
}
lines (-2,9,4,7)
## [[1]]
## [1] -0.3333333
##
## [[2]]
## [1] 6.324555
##
## [[3]]
## [1] 8.333333
## [1] "Thanks!"