try {
Console.WriteLine("请选择运算");
Console.WriteLine(@"
1`加法
2`减法
3`乘法
4`除法");
string strnum = Console.ReadLine();
int num = Convert.ToInt32(strnum);
int[] score = new int[2];
for (int i = 0; i < score.Length; i++)
{ Console.WriteLine("请输入第{0}个数字", i + 1);
score[i] = Convert.ToInt32(Console.ReadLine()); }
switch (num)
{
case 1:
Console.WriteLine("您得到的结果是{0}", jiafa(score));
break;
case 2:
Console.WriteLine("您得到的结果是{0}", jianfa(score));
break;
case 3:
Console.WriteLine("您得到的结果是{0}", chenfa(score));
break;
case 4:
Console.WriteLine("您得到的结果是{0}", chufa(score));
break;
} }
catch
{
Console.WriteLine("您输入的数字有误,请重新输入");
}
Console.ReadKey();
}
static int jiafa (int[] arr)
{
int a= 0;
for (int i = 0; i < arr.Length; i++)
{ a += arr[i]; }
return a;
}
static int jianfa (int []arr)
{
int b = 0;
b = arr[0] - arr[1];
return b;
}
static int chenfa(int[]arr)
{
int c = 0;
c = arr[0] * arr[1];
return c;
}
static int chufa(int []arr)
{
int d = 0;
d = arr[0] / arr[1];
return d;
}
网友评论