using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class
Program
{
static
void Main(string[]
args)
{
Console.WriteLine("Enter the first number.");
int
a = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Enter the second number.");
int
b = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("enter an operation to be performed (+,-,*,/)");
string
o = Console.ReadLine();
using if condition
if
(o.Trim() == "+")
{
Console.WriteLine(Convert.ToString(a+b));
}
else
if (o.Trim() == "-")
{
Console.WriteLine(Convert.ToString(a
- b));
}
else
if (o.Trim() == "*")
{
Console.WriteLine(Convert.ToString(a
* b));
}
else
if (o.Trim() == "/")
{
Console.WriteLine(Convert.ToString(a
/ b));
}
Console.WriteLine("end");
Console.ReadLine();
}
}
}
Using switch condition
switch (o.Trim())
{
case
"+":
Console.WriteLine(Convert.ToString(a + b));
break;
case
"-":
Console.WriteLine(Convert.ToString(a- b));
break;
case
"*":
Console.WriteLine(Convert.ToString(a * b));
break;
case
"/":
Console.WriteLine(Convert.ToString(a / b));
break;
}
Console.WriteLine("end");
Console.ReadLine();
No comments:
Post a Comment