In this program, You will learn how to find the remainder without using a modulus operator in R.
Example: How to find remainder without using modulus operator in R
1 2 3 4 5 6 7 8 9 10 11 12 13 |
{ x <- as.integer(readline(prompt = "Enter first number :")) y <- as.integer(readline(prompt = "Enter second number :")) while (x >= y) { x = x - y } print(paste("Remainder is :", x)) } |
This is a program written in the R programming language that prompts the user to enter two numbers, and then calculates the remainder of the first number divided by the second number. The remainder is then printed to the console.
The program first reads the two numbers from the user using the readline()
function and stores them in the variables x
and y
. It then enters a while
loop that continues until x
is less than y
. Inside the loop, x
is updated to be x - y
, which is the remainder of x
divided by y
. When the loop exits, x
contains the remainder and is printed to the console using the print()
function.
The output of this program would depend on the values of x
and y
that are entered by the user. Here is an example of what the output might look like:
1 2 3 4 5 |
Enter first number :5 Enter second number :2 [1] "Remainder is : 1" |