C# program to accept 2 integers and return remainder
Here's a C# program that accepts two integers from the user and returns the remainder when the first integer is divided by the second integer:
using System;
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the first integer: ");
int num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the second integer: ");
int num2 = Convert.ToInt32(Console.ReadLine());
int remainder = CalculateRemainder(num1, num2);
Console.WriteLine($"The remainder of {num1} divided by {num2} is: {remainder}");
}
static int CalculateRemainder(int dividend, int divisor)
{
return dividend % divisor;
}
}
In this program, the CalculateRemainder method takes two integers dividend and divisor as input and calculates the remainder when dividend is divided by divisor. It uses the modulo operator % to calculate the remainder.
The Main method prompts the user to enter the two integers, calls the CalculateRemainder method with the user inputs, and displays the calculated remainder.
Note that the program assumes the user will input valid integers. It doesn't handle exceptions if the input is not a valid integer or if the second integer (divisor) is zero.