Friday, 1 September 2017

c# tutorial programming | create calculator using switch case

Create Calculator Using Switch Case

Program

using System;
class Program
{
static void Main(string[] args)
{
int a, b, c;
Console.WriteLine("Number 1:");            
a = Convert.ToInt32(Console.ReadLine());          
Console.WriteLine("Number 2:");            
b = Convert.ToInt32(Console.ReadLine());           
Console.WriteLine("1. Add  2. Sub  3. Mul  4. div");            
int ch = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();            
switch (ch)
{
case1:
c = a + b;
Console.WriteLine("Addtion : {0}", c);
break;
case2:
c = a - b;
Console.WriteLine("Subtraction: {0}",c);
break;
case 3:
c = a * b;
Console.WriteLine("Multiplication: {0}",c);
break;
case 4:
c = a / b;
Console.WriteLine("Division: {0}",c);
break;
default:
Console.WriteLine("Invalid Choice");
break;
            }
        }
  }  

Output


0 comments:

Post a Comment