首页 > 编程知识 正文

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

时间:2023-05-03 06:07:25 阅读:209693 作者:4589

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: 10Enter second number: 20Addition of 10 and 20 is = 30 .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } 使用功能 (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: 10Enter second number: 20Addition of 10 and 20 is = 30

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

c#两个整数相除

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。