c#算术运算符_C#程序演示算术运算符的示例

c#算术运算符

Arithmetic operators are used to perform mathematic operations, here is the list of all C# arithmetic operators,

算术运算符用于执行数学运算,这是所有C#算术运算符的列表,

  1. "+" (Addition) – it is used to add two number, string concatenation

    “ +”(加法) –用于将两个数字加起来,字符串串联

  2. "-" (Subtraction) – it is used to subtract second operand from first operand

    “-”(减法) –用于从第一个操作数中减去第二个操作数

  3. "*" (Multiplication) – it is used to multiply two operands

    “ *”(乘法) –用于将两个操作数相乘

  4. "/" (Divide) – it is used to divide numerator from de-numerator

    “ /”(除法) –用于将分子与去分子相除

  5. "%" (Modulus) - it is used to get remainder

    “%”(模量) -用于获取余数

Example:

例:

    Input:
    int a = 10;
    int b = 3;

    //operations
    int sum = a + b;
    int sub = a - b;
    int mul = a * b;
    float div = (float)a / (float)b;
    int rem = a % b;

    Output:
    sum = 13
    sub = 7
    mul = 30
    div = 3.333333
    rem = 1

C# code to demonstrate example of arithmetic operators

C#代码演示算术运算符的示例

// C# program to demonstrate example of 
// arithmetic operators 
using System;
using System.IO;
using System.Text;

namespace IncludeHelp
{
    class Test
    {
        // Main Method 
        static void Main(string[] args)
        {
            int a = 10;
            int b = 3;

            int sum = a + b;
            int sub = a - b;
            int mul = a * b;
            float div = (float)a / (float)b;
            int rem = a % b;

            Console.WriteLine("Addition of {0} and {1} is = {2}", a, b, sum);
            Console.WriteLine("Subtraction of {0} and {1} is = {2}", a, b, sub);
            Console.WriteLine("Multiplication of {0} and {1} is = {2}", a, b, mul);
            Console.WriteLine("Division of {0} and {1} is = {2}", a, b, div);
            Console.WriteLine("Remainder of {0} and {1} is = {2}", a, b, rem);

            //hit ENTER to exit the program
            Console.ReadLine();
        }
    }
}

Output

输出量

Addition of 10 and 3 is = 13
Subtraction of 10 and 3 is = 7
Multiplication of 10 and 3 is = 30
Division of 10 and 3 is = 3.333333
Remainder of 10 and 3 is = 1


翻译自: https://www.includehelp.com/dot-net/arithmetic-operators-example-in-c-sharp.aspx

c#算术运算符

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值