C# Program to find remainder without using the modulus operator
In this program, You will learn how to find the remainder without using a modulus operator in C#.
0 = 10 % 5
5 = 5 % 10
Example: How to find the remainder without using the modulus operator in C#.
using System;
public class Test
{
public static void Main(string[] args)
{
int x, y;
Console.Write("Enter first number:");
x = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter second number:");
y = Convert.ToInt32(Console.ReadLine());
while (x >= y)
{
x = x - y;
}
Console.WriteLine("Remainder is:" + x);
}
}
Output:
Enter first number:12
Enter second number:5
Remainder is:2