# CSharp - Write program to Integer Division and Remainder

## Requirements

33 divided by 7 can either 4.71428 or 4 with remainder 5. It is called Integer Division.

You will do integer division differently from normal division.

## Hint

In C#, you use the same operator, the slash (/), for both types.

If you put a slash between two values of the int type, the slash performs integer division.

If at least one of the two values is of double type, the slash performs normal division.

You will do normal and integer divisions of the two numbers entered by the user.

To compute the remainder, you use the % operator (percent sign).

You have the following two ways to force the entered values to doubles to achieve "normal" division.

• Assignment to variables of type double.
• Type cast to double.

## Demo

using System;
class Program{//from   w w  w  .java2  s.  com
static void Main(string[] args)
{
// Inputs
Console.Write("Enter 1. whole number (dividend): ");
int number1 = Convert.ToInt32(input1);

Console.Write("Enter 2. whole number (divisor): ");
int number2 = Convert.ToInt32(input2);

// Integer calculations
int integerQuotient = number1 / number2;
int remainder = number1 % number2;

// "Normal" calculations
double number1double = number1;
double number2double = number2;
double normalQuotient = number1double / number2double;

// Alternatively
double normalQuotientAlternatively = (double)number1 / (double)number2;

// Outputs
Console.WriteLine("Integer quotient: " + integerQuotient + " with remainder " + remainder);
Console.WriteLine("\"Normal\" quotient : " + normalQuotient);
Console.WriteLine("\"Normal\" quotient (alternatively): " + normalQuotientAlternatively);
}
}