What modification is needed so function returns a sequence without the number 1 duplicated?
myfib<- function(){
fib.a<-1
fib.b<- 1
cat(fib.a,", ",fib.b,",",sep="")
repeat{
temp<- fib.a+fib.b
fib.a<-fib.b
fib.b<-temp
cat(fib.b,", ", sep="")
if(fib.b>150){
cat("BREAK NOW...")
break
}
}
}
instead of
1, 1, 2, 3, 4, 8, 13, 21, 34, 55, 89, 144, 233, BREAK NOW...
return
1, 2, 3, 4, 8, 13, 21, 34, 55, 89, 144, 233, BREAK NOW...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…