Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write an R program to check if a given vector contains a specific element.

Easy

Problem Statement

Write an R program to check if a given vector contains a specific element.

Sample Input

Vector: c(1, 2, 3, 4, 5)
Element: 3

Sample Output

Element 3 is present in the vector

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
# Predefined structure vector <- c(1, 2, 3, 4, 5) element <- 3 if (element %in% vector) { print(paste("Element", element, "is present in the vector"))} else { print(paste("Element", element, "is not present in the vector"))}
Log in or sign up to run or submit your code.Log inSign up
Input
Vector: c(1, 2, 3, 4, 5)
Element: 3
Expected Output
Element 3 is present in the vector