C# Program to perform Addition, Subtraction, Multipilcation and Division operation.

The following program perform mathematical operation such as Addition, Subtraction, Multipilcation and Division operation.

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

namespace ConsoleApplication1
{
class Program
{
int Number1, Number2;
char option;
int Result;

public void Number()
{
Console.WriteLine("Enter the First Number:");
Number1 = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter the Second Number:");
Number2 = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Main Menu");
Console.WriteLine("1. Addition");
Console.WriteLine("2. Subtraction");
Console.WriteLine("3. Multiplication");
Console.WriteLine("4. Division");

Console.WriteLine("Enter the Operation you want to perform");
option = Convert.ToChar(Console.ReadLine());

switch (option)
{
case '1':
Result = Number1 + Number2;
Console.WriteLine("The result of Addition is:{0}", Result);
break;
case '2':
Result = Number1 - Number2;
Console.WriteLine("The result of Subtraction is:{0}", Result);
break;
case '3':
Result = Number1 * Number2;
Console.WriteLine("The result of Multiplication is:{0}", Result);
break;
case '4':
Result = Number1 / Number2;
Console.WriteLine("The result of Division is:{0}", Result);
break;
default:
Console.WriteLine("Invalid Option");
break;
}
Console.ReadLine();
}

static void Main(string[] args)
{
Program objProgram = new Program();
objProgram.Number();            
}
}
} 

Output:

0 comments:

Post a Comment

 

About Me

It's Me!Hi, I'm Moinuddin. I'm a Software Engineer at WIPRO working on Microsoft .NET Technology. I'm interested in a wide range of technology topics, mainly Microsoft including Windows Azure, WCF, WPF, Silverlight and any other cool technology that catches the eye.

Site Info

ProjectCSharp.com is mainly about demonstrating real time examples in different technologies like ASP.NET, WCF, WPF, Silverlight, Azure etc..,

Followers

Help Links

Project CSharp (C#) Copyright © 2011. All Rights Reserved.