Programming Code Examples

R Program to Take Input From User1 min read

Here is an example of an R program that prompts the user to enter two numbers and then adds them:

This program reads the numbers from the user using the readline() function and stores them in the variables x and y. It then converts the strings that are read from the user into numeric values using the as.numeric() function.

Next, it adds the numbers using the + operator and stores the result in a new variable z. Finally, it prints the contents of z to the console using the print() function.

Here is an example of what the output of this program might look like:

This program reads two numbers from the user, adds them together, and prints the result to the console.

Add comment