c#两个整数相除_C#| 找到两个整数相加

c#两个整数相除

Given (input) two integer numbers and we have to find the addition of given number in C#.

给定(输入)两个整数,我们必须在C#中找到给定数字的加法。

Example:

例:

    Input:
    First number: 10
    Second number: 20

    Output:
    Addition of 10 and 20 is = 30

Program:

程序:

using System;
class AddTwoNumbers {
    static void Main() {
        try{
            //declare two variables
            int a = 0;
            int b = 0;
            
            //input numbers
            Console.Write("Enter first number: ");
            a = Convert.ToInt32(Console.ReadLine());
            Console.Write("Enter second number: ");
            b = Convert.ToInt32(Console.ReadLine());            
            
            //calculating sum
            int sum = a+b;
            
            Console.WriteLine("Addition of " + a + " and " + b + " is = " + sum);
        }
        catch(Exception ex){
            Console.WriteLine("Error: " + ex.ToString());
        }
    }
}

Output

输出量

Enter first number: 10
Enter second number: 20
Addition of 10 and 20 is = 30


使用功能 (Using function)

Here, we are defining a function that will take two integer arguments and return the sum of the numbers.

在这里,我们定义了一个函数,该函数将接受两个整数参数并返回数字的总和。

Program:

程序:

using System;
class AddTwoNumbers {
    //defining function
    static int sumOfTwoNumber(int x, int y){
        return x+y;
    }
    //main function
    static void Main() {
        try{
            //declare two variables
            int a = 0;
            int b = 0;
            
            //input numbers
            Console.Write("Enter first number: ");
            a = Convert.ToInt32(Console.ReadLine());
            Console.Write("Enter second number: ");
            b = Convert.ToInt32(Console.ReadLine());            
            
            //calculating sum by calling the function
            int sum = sumOfTwoNumber(a,b);
            
            Console.WriteLine("Addition of " + a + " and " + b + " is = " + sum);
        }
        catch(Exception ex){
            Console.WriteLine("Error: " + ex.ToString());
        }
    }
}

Output

输出量

Enter first number: 10
Enter second number: 20
Addition of 10 and 20 is = 30


翻译自: https://www.includehelp.com/dot-net/addition-of-two-integer-numbers.aspx

c#两个整数相除

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值