n <- as.numeric(n)
b <- c()
for (i in 2:(n-1))
{
a <- (n%%i)
if (a==0) {
b <- print(i)
}
}
ouput
n <- readline(prompt = "Enter the value of n:")
Enter the value of n:10
> n <- as.numeric(n)
> b <- c()
> for (i in 2:(n-1))
+ {
+ a <- (n%%i)
+ if (a==0) {
+ b <- print(i)
+ }
+
+ }
[1] 2
[1] 5
I want my output in vector form. I am not sure what to do.I ve tried this one method I saw in other answers but couldnt succeed .
b <- c(b,i)perhaps (instead of your line withprint(b)in it)?