R Program to Find the Sum of Natural Numbers

bookmark

# take input from the user
num = as.integer(readline(prompt = "Enter a number: "))

if(num  0) {
        sum = sum + num
        num = num - 1
    }

    print(paste("The sum is", sum))
}


Output

Enter a number: 10
[1] "The sum is 55"