You are on page 1of 1

NAME: DAKSHIT CHOPRA DATE: 17/04/2023

REG. NO.: RA2011003030243


BATCH: CSE K

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) {

sum <- sum + i

print(paste("The sum of the first 100 natural numbers is", sum))

OUTPUT:

You might also like