Find factors using R Programming Language

Discover factors in R programming! Learn how to find factors effortlessly with the powerful R language, exploring the basics of factorization and enhancing your data manipulation skills.

Program:

print_factors <- function(x) {
print(paste("The factors of",x,"are:"))
for(i in 1:x) {
if((x %% i) == 0) {
print(i)
}
}
}

Output:

The factors of 24 are:"
[1] 1
[1] 2
[1] 3
[1] 4
[1] 6
[1] 8
[1] 12
[1] 24

 

Built function:

print_factors() is a user-defined function.
print_factors(24)
[1] "The factors of 24 are:"
[1] 1
[1] 2
[1] 3
[1] 4
[1] 6
[1] 8
[1] 12
[1] 24
Scroll to Top