Professional Documents
Culture Documents
CPS – III
LAB – 15
AIM: Coding Implementing using ‘R’ Programming.
Write a R program to get all prime numbers up to a given number.
ALGORITHM:
1. Initialize a variable sum to 0.
2. Start a for loop that iterates from 1 to 100.
3. Within the loop, add the loop variable i to the sum variable.
4. After the loop has completed, print the sum of the first 100 natural numbers
using the print function and the paste function to concatenate strings.
5. End the program.
CODE:
# Calculate the sum of the first 100 natural numbers
sum <- 0
for (i in 1:100) {
OUTPUT: