Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
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
Please
log in
to post a comment.
Test
ProgramasR
Project2.Question1
14-09-2020QRajustelinear
Graph
practica 4
practical ml
Spiral
direct_assignment
Ass2 q2
Please log in to post a comment.