R Lang

R Program to display even numbers from 1 to 1002 min read

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

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




The code uses a for loop to iterate over a sequence of numbers from 1 to 100. For each iteration of the loop, the loop variable num takes on the value of the current number in the sequence.

Inside the loop, the code uses the if statement to check if num is even by using the modulo operator (%%) to compute the remainder of num divided by 2. If the remainder is 0, it means that num is evenly divisible by 2 and therefore is even. If num is even, the code prints a message to the console saying that num is an even number.

This code will print all even numbers between 1 and 100 to the console, but it will not print the odd numbers.

Output:

Leave a Comment