# C# | Find the addition of two integer numbers

C# program to find the addition of two integer numbers: Here, we are writing a C# program that will read two integer numbers and find their sum.
Submitted by IncludeHelp, on December 05, 2018

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

Example:

```    Input:
First number: 10
Second number: 20

Output:
Addition of 10 and 20 is = 30
```

Program:

```using System;
static void Main() {
try{
//declare two variables
int a = 0;
int b = 0;

//input numbers
Console.Write("Enter first number: ");
Console.Write("Enter second number: ");

//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;
//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: ");
Console.Write("Enter second number: ");

//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
```

TOP Interview Coding Problems/Challenges

Learn PCB Designing: PCB DESIGNING TUTORIAL

 Recommended posts C Tips & Tricks, C++ Tips & Tricks Introduction to Linux (Its modes, Safety, Most popular Applications) Linux Best Distros of 2018 C programming optimization techniques Differences b/w C & Embedded C? Embedded C Interview Q. & A. C programming tips for Embedded Development Basic rules of writing a C program Important points (rules) to remember while writing C/C++ program Top 5 Websites for solving programming challenges Read more...

 Others... Computer G.K. (MCQ) Most viewed pages... Categories...

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates