On 12/02/2012 10:57 PM, Mkkl wrote:
function<- function(p){
i<- 2
r<- 0
while(i< p) {
q<- (p/i)
while(q>=1) {
q=(q-1)
}
if (q==0) {
r=1
} else
i=i+1
}
return(r)
}
This f
Hello,
Because p/i == 4/2 == 2 thenyou subtract 1 unil q == 0 and i = i+1 is
never executed.
(Use print statements to check it.)
Hope this helps,
Rui Barradas
Em 02-12-2012 11:57, Mkkl escreveu:
function <- function(p){
i <- 2
r <- 0
while(i < p) {
q <- (p/i)
while(q
function <- function(p){
i <- 2
r <- 0
while(i < p) {
q <- (p/i)
while(q>=1) {
q=(q-1)
}
if (q==0) {
r=1
} else
i=i+1
}
return(r)
}
This function stays in some kind of loo
3 matches
Mail list logo