# Create a vector of numbers with variable length
numbers <- c(2, 7, 10, 15, 8, 3, 6)
# Initialize an empty vector to store the results
results <- vector()
# Use a for loop to iterate through the numbers
for (num in numbers) {
# Check if the number is even or odd
if (num %% 2 == 0) {
result <- "Even"
} else {
result <- "Odd"
}
# Append the result to the results vector
results <- c(results, result)
}
# Print the original vector and the results
cat("Original Vector: ", numbers, "\n")
cat("Classification: ", results, "\n")
0 Comments