在C#中使用除法运算符将分子除以分母,例如9/3
除法运算符属于C#中的算术运算符。让我们看一个完整的示例,学习如何在C#中实现算术运算符,其中我们将了解如何使用除法运算符。
result = num1 / num2; Console.WriteLine("Division: Value is {0}", result);
上面我们在num1和num2上使用了除法运算符。
以下是完整的示例。
using System; namespace Sample { class Demo { static void Main(string[] args) { int num1 = 50; int num2 = 25; int result; result = num1 + num2; Console.WriteLine("Value is {0}", result); result = num1 - num2; Console.WriteLine("Value is {0}", result); result = num1 * num2; Console.WriteLine("Value is {0}", result); result = num1 / num2; Console.WriteLine("Division: Value is {0}", result); result = num1 % num2; Console.WriteLine("Value is {0}", result); result = num1++; Console.WriteLine("Value is {0}", result); result = num1--; Console.WriteLine("Value is {0}", result); Console.ReadLine(); } } }
输出结果
Value is 75 Value is 25 Value is 1250 Division: Value is 2 Value is 0 Value is 50 Value is 51