0

Why my program does not work? I want to print n in every cycle, which it will be comparing if number n is divisible by 2, or divisible by 3 and 5 or divisible by none of these numbers. Thanks for help.

funkcia = function(n){
    for (i in 1:n){
        if (n/2 == 0){
            n = n*n
            print (n)
            
        }
        else if(n/3 == 0 & n/5 == 0){
            n =n*n*n
            print(n)
            
        }
        
        else {
            n = n
            print(n)
        }
       
    }
    
}
zx8754
  • 52,746
  • 12
  • 114
  • 209
OnlyForFun
  • 43
  • 5
  • 1
    Read about `%%` and `%/%`, see `?Arithmetic`. Also, read about floating points: https://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal – zx8754 Apr 07 '22 at 12:18
  • `n/2 == 0` only occurs when n == 0... – Wimpel Apr 07 '22 at 12:40
  • To zx8754's comment: https://stat.ethz.ch/R-manual/R-devel/library/base/html/Arithmetic.html – r2evans Apr 07 '22 at 12:41

0 Answers0