OnlyForFun
OnlyForFun

Reputation: 53

How to check if is a number divisible

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)
        }
       
    }
    
}

Upvotes: 0

Views: 177

Answers (0)

Related Questions