division c# code example
Example 1: C# remainder
using System;
public class Example
{
public static void Main()
{
Decimal[] dividends = { 79m, 1000m, -1000m, 123m, 1234567800000m,
1234.0123m };
Decimal[] divisors = { 11m, 7m, 7m, .00123m, 0.12345678m, 1234.5678m };
for (int ctr = 0; ctr < dividends.Length; ctr++)
{
Decimal dividend = dividends[ctr];
Decimal divisor = divisors[ctr];
Console.WriteLine("{0:N3} / {1:N3} = {2:N3} Remainder {3:N3}", dividend,
divisor, Decimal.Divide(dividend, divisor),
Decimal.Remainder(dividend, divisor));
}
}
}
Example 2: divide 3 numbers c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo {
class MyApplication {
static void Main(string[] args) {
int num;
num = 15;
Console.WriteLine("Number: "+num);
if (num % 3 == 0 && num % 5 == 0) {
Console.WriteLine("Divisible by 3 and 5");
} else {
Console.WriteLine("Not divisible by 3 and 5");
}
Console.ReadLine();
}
}
}