Written by Siddartha Thota on January 28, 2013 in C# > Programming

Basic Arithmetic C# Program

GET ALERTS:

Get our Latest updates delivered to your mailbox!

This is absolutely basic Arithmetic C# program, created just to make sure that it helps you to get started with C#. In this programming tutorial, we tend to initialize a couple of integers and our task is to perform some of the basic arithmetic functions like sum, difference, product, average, square, and reminder, for the values that we initialized.

In order to compile a C# program, you need to have Visual Studio, preferably 2008+.

Launch Visual Studio and click on New Project, and in the templates section on the left, select Visual C# and then select “Console Application” module, in order to compile your project in console, else you can just select “Windows Forms Application” which will be running with set of labels/buttons/text boxes. In this project, I’m preferring to get started with Console Application. Finally, click on OK button.

After selecting the Console Application, you need to name your project. If not, you’ll have to adjust with the default name created with the Visual Studio.

C# basic arithmetic

Just make sure that, you follow all the steps mentioned above and please do check the image instructions as well.

You’ll be redirected into the project page, where you’ll be writing your code. The project page appears like this.

programmingunitSo, Let us check out the Code for C# Basic Arithmetic Program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace arthema //namespace must have same name as your project name
{
     class Program
     {
             static void Main(string[] args) //Main Function
            {
                   int a = 199; //initialization
                   int b = 76; // initialization
                   int c = a + b;
                   Console.WriteLine("Sum of 2 Digits :" + c);
                   int d = a - b;
                   Console.WriteLine("Difference of 2 Digits: " + d);
                   int e = a * b;
                   Console.WriteLine("Product of 2 Digists: " + e);
                   double f = (double)(a + b) / 2;
                   Console.WriteLine("Average of 2 Digits: " + f);
                   int g = a * a;
                   Console.WriteLine("Square of first digit: " + g);
                   int h = b * b;
                  Console.WriteLine("Square of second digit: " + h);
                  int i = a % b;
                  Console.WriteLine("Reminder of 2 Digits: " + i);
             }
      }
}

Output :

output C#

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: