作者celestialgod (天)
看板R_Language
标题Re: [问题] 关於使用者自行输入值的问题
时间Wed Mar 16 12:01:23 2016
※ 引述《HumuHumu (呼姆呼姆)》之铭言:
: 请问我要怎麽写一个程式如下:
: 使用者自行输入一个数字,显示所有小於此数的质数?
: 有查到是用readline
: 可是我写好以後
: 他不等我输入完数字就直接跑後面的程式
: 我的目标是:画面出现"请输入质数上限"後
: 我输入一个数字,才开始显示小於此数的所有质数
: 我写的检视质数程式码如下(目前质数上限为100,我想要让这个100可以使用者自行输入):
: library(numbers)
: x=1
: while (x<=100){
: if(isPrime(x)==TRUE){
: print(x)
: x=x+1
: }else{
: x=x+1
: }
: }
: 小弟还是初学者,请多包涵
: -----
: Sent from JPTT on my HTC_B810x.
library(numbers)
print_primes_f <- function(){
n <- readline(prompt="Enter an integer: ")
Primes(2L, as.integer(n))
}
print_primes_f()
# Enter an integer: 100
# [1] 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71
# [21] 73 79 83 89 97
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.109.74.87
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1458100887.A.D34.html
1F:推 HumuHumu: Primes(2L, as.integer(n)) 03/16 14:17
2F:→ HumuHumu: 请问这行是什麽意思呢 03/16 14:18
3F:→ celestialgod: ?Primes 03/16 14:34