0
How to draw stars in R?
You need to create a function that takes a number X as its parameter and outputs X stars using the asterisk symbol *. Sample Input 4 Sample Output [1] "*" [1] "*" [1] "*" [1] "*"
3 Respostas
+ 3
Use loop to print *
0
x <- readLines('stdin')
x <- as.integer(x[1])
#define the function
stars<- function(x) {
for (i in 1:x)
print('*')
}
stars(x)
0
#Create a function that takes a number X as its parameter and outputs X stars using the asterisk symbol
astric <- function(x){
y<-as.integer(0)
while (y!=x){
print("*")
y<-y+1
}
}
astric(5)