-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday 5.R
67 lines (43 loc) · 1017 Bytes
/
day 5.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
x <- 1:3
print(x)
y <- seq(2, 10, 3)
print(y)
print(sum(20:40))
print(mean(20:30))
value <- 50:10
d <- 40:99
mean_function <- function(value){
len <- length(value)
sum_value <- 0
for (i in value ){
sum_value = i + sum_value
}
mean_val <- sum_value/len
mean_val
}
mean_function(d)
factorial_func <- function(x){
count_val <- 1 :nchar(x)
fac <- 1
for (i in count_val){
fac <- i*fac
}
print(fac)
}
factorial_func("katie")
volume_cube <- function(a, b, c){
vol <- a*b*c
print(vol)
}
volume_cube(30, 25, 40)
age_function <- function(c_y, b_y, name){
age <- c_y - b_y
z <- paste(name, "is ", age, "years old", sep = " ")
print(z)
}
c_y <- as.numeric(readline(prompt="enter current year: "))
b_y <- as.numeric(readline(prompt="enter year of birth: "))
name <- readline(prompt="enter name: ")
age_function(c_y, b_y, name)
list_a <- list(c(1, 2, 3), c(2, 4, 6), c(7, 8, 9))
print(list_a[1])