Program For Add, Subtract, Multiply, Divide in C#

Write a program that allows you to input two numbers. Based on the option chosen from a menu you the numbers will be:

  • Added together or;
  • Second number subtracted from first number or;
  • Multiply numbers together or
  • first number is divided by the second number;

Procedure:-

  1. Go to File, NewàProject, Select Window Classic DesktopàConsole App (.net Framework).
  2. Take three Variable (num1, num2 and output) and declare as integer.
  3. num1 and num2 is input value taken from users and output variable perform the operation.
  4. Take four menus to perform the desired task.
  5. On opting from menu the task will perform.
  6. If you choose invalid option then program will break.

C# Code: -

{`
using System;
using System.Collections.Generic;
using System.Text;
namespace Program
{
className Program
{
static void Main(string[] args)
{
int Num1, Num2, output;
char option;
Console.Write("Enter the First Number : ");
Num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the Second Number : ");
Num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Main Menu");
Console.WriteLine("1. Added together or;");
Console.WriteLine("2. Second number subtracted from first number or;");
Console.WriteLine("3. Multiply numbers together or");
Console.WriteLine("4. first number is divided by the second number;");
Console.Write("Enter the option from the above list to perform the task: ");
option = Convert.ToChar(Console.ReadLine());
switch (option)
{
case '1':
output = Num1 + Num2;
Console.WriteLine("The result of Addition is : {0}", output);
break;
case '2':
output = Num1 - Num2;
Console.WriteLine("The result of Subtraction is : {0}", output);
break;
case '3':
output = Num1 * Num2;
Console.WriteLine("The result of Multiplication is : {0}",output);
break;
case '4':
output = Num1 / Num2;
Console.WriteLine("The result of Division is : {0}", output);
break;
default:
Console.WriteLine("Invalid Option");
break;
}
Console.ReadLine();
}
}
}`}

C# Program Output

Program Output For Add, Subtract, Multiply, Divide in C Sharp
citation generator
citaion generator
make money online