R Program to display even numbers from 1 to 100


In this program, You will learn how to display even numbers from 1 to 100 in R.


if( num %%2 == 0){ 
   //statement 
}

else { 
   //statement
}

Example: How to display even numbers from 1 to 100 in R

for (num in 1:100) {
 if (num %% 2 == 0) {
   print(paste("Even number is :", num))
 }
}

Output:

[1] "Even number is : 2"
[1] "Even number is : 4"
[1] "Even number is : 6"
[1] "Even number is : 8"
[1] "Even number is : 10"
[1] "Even number is : 12"
[1] "Even number is : 14"
[1] "Even number is : 16"
[1] "Even number is : 18"
[1] "Even number is : 20"
[1] "Even number is : 22"
[1] "Even number is : 24"
[1] "Even number is : 26"
[1] "Even number is : 28"
[1] "Even number is : 30"
[1] "Even number is : 32"
[1] "Even number is : 34"
[1] "Even number is : 36"
[1] "Even number is : 38"
[1] "Even number is : 40"
[1] "Even number is : 42"
[1] "Even number is : 44"
[1] "Even number is : 46"
[1] "Even number is : 48"
[1] "Even number is : 50"
[1] "Even number is : 52"
[1] "Even number is : 54"
[1] "Even number is : 56"
[1] "Even number is : 58"
[1] "Even number is : 60"
[1] "Even number is : 62"
[1] "Even number is : 64"
[1] "Even number is : 66"
[1] "Even number is : 68"
[1] "Even number is : 70"
[1] "Even number is : 72"
[1] "Even number is : 74"
[1] "Even number is : 76"
[1] "Even number is : 78"
[1] "Even number is : 80"
[1] "Even number is : 82"
[1] "Even number is : 84"
[1] "Even number is : 86"
[1] "Even number is : 88"
[1] "Even number is : 90"
[1] "Even number is : 92"
[1] "Even number is : 94"
[1] "Even number is : 96"
[1] "Even number is : 98"
[1] "Even number is : 100"