You are viewing a single comment's thread from:
RE: 01. LPTHW (A Good First Program - ex1.py) || Announcement of the winners of the last challenge. || New challenges at the end.
#Assign 100 as the length of the fibonacci series with an assumption that 400000 will fall within this length
#fibvals is the fibonaci series with length 100
len <- 100
fibvals <- numeric(len)
#assign values 1,1 to the first two elements of Fiboonacci series
fibvals[1] <- 1
fibvals[2] <- 1
#from 3rd element to 100th element generate Fibonacci series till it is less than 400,000
for (i in 3:len)
{
if(fibvals[i-1]+fibvals[i-2] > 400000)
{
break
}
else
fibvals[i] <- fibvals[i-1]+fibvals[i-2]
}
#Sum of all the even numbers in the series (division of the series element with 2 should be 0)
sum(fibvals[fibvals %% 2 ==0])
good
I've upvote you, now it's your turn upvote my post @abiismail
please go to the link below
https://steemit.com/travel/@abiismail/belanja-hemat-di-swalayan-nanggroe-
637b52e3706bc
https://steemit.com/travel/@abiismail/suasana-piknik-pagi-di-pantai-laut-syiah-kuala-e0e6fadf3b145