Program to perform all Arithmetic operations over two integer values using Switch Statement In C#.
Code:
class Program
{
static void Main(string[] args)
{
int a, b,c;
Console.WriteLine("Enter the first number");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the second number");
b = Convert.ToInt32(Console.ReadLine());
int result;
while(true)
{
Console.WriteLine("Press 0 for Addition");
Console.WriteLine("Press 1 for Subtraction");
Console.WriteLine("Press 2 for Multiplication");
Console.WriteLine("Press 3 for Division");
Console.WriteLine("Press 4 for Modulus");
Console.WriteLine("Enter the input");
c = Convert.ToInt32(Console.ReadLine());
switch(c)
{
case 0:
result = a + b;
Console.WriteLine("The result is" + result);
break;
case 1:
result = a - b;
Console.WriteLine("The result is" + result);
break;
case 2:
result = a * b;
Console.WriteLine("The result is" + result);
break;
case 3:
result = a / b;
Console.WriteLine("The result is" + result);
break;
case 4:
result = a % b;
Console.WriteLine("The result is" + result);
break;
default:
{
Environment.Exit(0);
}
break;
}
}
}
}
No comments:
Post a Comment