效果
14494383-899f6106110c56c0.png
代码
double c = 0;
Console.WriteLine("请选择一个运算符 1.加法\t2.减法\t3.乘法\t4.除法");
int shuzi1 = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入数字a:");
Double a1 = Convert.ToDouble(Console.ReadLine());
Console.Write("请输入数字b:");
Double b1 = Convert.ToDouble(Console.ReadLine());
double jieguo = Suanshu(shuzi1, a1, b1, c);
Console.WriteLine("*****运算结果为:{0}",jieguo);
Console.ReadKey();
}
static Double Suanshu(int shuzi, Double a, Double b, Double c)
{
switch (shuzi)
{
case 1:
c = a + b;
break;
case 2:
c = a - b;
break;
case 3:
c = a * b;
break;
case 4:
c = a / b;
break;
}
return c;
}
网友评论