用C#编写一个简易计算器,麻烦把程序写出来。

要求见图。
要求是这样的:
1、接收2个int类型的操作数和1个运算符(+、-、*、/),完成相应的算数运算,输出运算结果。
2、编写4个方法分别完成加减乘除运算,操作数作为方法的参数,运算结果作为方法的ref或者out参数。

第1个回答  2011-09-20
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
private static double c = 0;
private static double comp(int a, int b,string sig)
{
if(sig == "+"){ c = a + b;}
if(sig == "-"){ c = a - b;}
if(sig == "*"){ c = a*b;}
if(sig == "/" && b!=0){ c = a/b;}
return c;
}
static void Main(string[] args)
{
double result=0;
Console.WriteLine("请输入两个操作数及运算符:");
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
char opr= Convert.ToChar(Console.ReadLine());
result = comp(a, b,opr);
Console.WriteLine(result);
Console.ReadLine();
}
}
}本回答被提问者和网友采纳
第2个回答  2011-09-19
百度一下 网上有源码 自己修改下就行了
相似回答