Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
sum of digits is prime
# Function to check if the number is TRUE or FALSE checkPrime <- function(number) { if (number == 2) { TRUE } else if (any(number %% 2:(number-1) == 0)) { FALSE } else { TRUE } } # Function to return sum of the digits digitsum <- function(x) sum(floor(x / 10^(0:(nchar(x) - 1))) %% 10) # loop from 10 to 200 num=10 while (num <= 200) { # Check the sum of digits here n=num s=0 while (n > 0) { r = n %% 10 s = s + r n = n %/% 10 } # check if prime if(checkPrime(s)){ message("sum=",s," => num=",num) } # Update num value num = num+1 }
run
|
edit
|
history
|
help
0
example
Exercise 3 Matrices NBA TEST
Xprod
Distribution stable under iteration
Sierpinski curve
SampleDiscrFR.r
19-08-2020-JacobiSistemaNewtonaprpx
Linear regression Model [Empirical Models]
Peso diário
16-09-2020ExVitorb