R study notes

Friday, October 3, 2014

Class assignment: fibonacci

fibonacci<-function(n)
{#functioin start
 a=1
 b=1
 for (i in 1:n)
     {  temp=b
      b=a
      cat(sprintf("b=%d\n",b))
      a=a+temp
      cat(sprintf("  a=%d\n",a))
      }
 print(a)
}#function end
fibonacci(4)
fibonacci(1)
fibonacci(9)
Posted by little6 at 4:59 PM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

About Me

little6
View my complete profile

Blog Archive

  • ►  2015 (2)
    • ►  November (1)
    • ►  February (1)
  • ▼  2014 (58)
    • ►  November (9)
    • ▼  October (29)
      • R语言系列:简单作图
      • R语言矩阵运算
      • R语言绘图 制图的一些要点
      • Exercise-11
      • Exercise-10
      • Exercise-9
      • Exercises-8
      • Random Code in Class 10/13/2014
      • Exercises-3
      • Exercises-2
      • Exercises-1
      • sets {base}
      • match
      • The %in% operator in R
      • R软件中排序:sort(),rank(),order()
      • R unname Function
      • R dim Function
      • “e” 科学记数:
      • Printing Fewer Digits (or More Digits)
      • Complex
      • statistical info
      • %%, %/% operators
      • cat
      • get
      • R书精选
      • Finding and removing duplicate records
      • Class assignment: fibonacci
      • Writing text and output from analyses to a file
      • R基本数据类型转换?
    • ►  September (20)
Simple theme. Powered by Blogger.