如何用c#编写计算器代码(只要加减乘除)

如何用c#编写计算器代码(只要加减乘除),第1张

using System;\x0d\using SystemDrawing;\x0d\using SystemCollections;\x0d\using SystemComponentModel;\x0d\using SystemWindowsForms;\x0d\using SystemData;\x0d\\x0d\namespace jisuan\x0d\{\x0d\ /// \x0d\ /// Form1 的摘要说明。\x0d\ /// \x0d\ public class Form1 : SystemWindowsFormsForm\x0d\ {\x0d\ private SystemWindowsFormsTextBox textBox1;\x0d\ private SystemWindowsFormsTextBox textBox2;\x0d\ private SystemWindowsFormsTextBox textBox3;\x0d\ private SystemWindowsFormsComboBox comboBox1;\x0d\ private SystemWindowsFormsButton button1;\x0d\ private SystemWindowsFormsButton button2;\x0d\ private SystemWindowsFormsButton button3;\x0d\ /// \x0d\ /// 必需的设计器变量。\x0d\ /// \x0d\ private SystemComponentModelContainer components = null;\x0d\\x0d\ public Form1()\x0d\ {\x0d\ //\x0d\ // Windows 窗体设计器支持所必需的\x0d\ //\x0d\ InitializeComponent();\x0d\\x0d\ //\x0d\ // TODO: 在 InitializeComponent 调用后添加任何构造函数代码\x0d\ //\x0d\ }\x0d\\x0d\ /// \x0d\ /// 清理所有正在使用的资源。\x0d\ /// \x0d\ protected override void Dispose( bool disposing )\x0d\ {\x0d\ if( disposing )\x0d\ {\x0d\ if (components != null) \x0d\ {\x0d\ componentsDispose();\x0d\ }\x0d\ }\x0d\ baseDispose( disposing );\x0d\ }\x0d\\x0d\ #region Windows 窗体设计器生成的代码\x0d\ /// \x0d\ /// 设计器支持所需的方法 - 不要使用代码编辑器修改\x0d\ /// 此方法的内容。\x0d\ /// \x0d\ private void InitializeComponent()\x0d\ {\x0d\ thistextBox1 = new SystemWindowsFormsTextBox();\x0d\ thistextBox2 = new SystemWindowsFormsTextBox();\x0d\ thistextBox3 = new SystemWindowsFormsTextBox();\x0d\ thiscomboBox1 = new SystemWindowsFormsComboBox();\x0d\ thisbutton1 = new SystemWindowsFormsButton();\x0d\ thisbutton2 = new SystemWindowsFormsButton();\x0d\ thisbutton3 = new SystemWindowsFormsButton();\x0d\ thisSuspendLayout();\x0d\ // \x0d\ // textBox1\x0d\ // \x0d\ thistextBox1Location = new SystemDrawingPoint(24, 72);\x0d\ thistextBox1Name = "textBox1";\x0d\ thistextBox1Size = new SystemDrawingSize(100, 21);\x0d\ thistextBox1TabIndex = 0;\x0d\ thistextBox1TextChanged += new SystemEventHandler(thistextBox1_TextChanged);\x0d\ // \x0d\ // textBox2\x0d\ // \x0d\ thistextBox2Location = new SystemDrawingPoint(312, 72);\x0d\ thistextBox2Name = "textBox2";\x0d\ thistextBox2Size = new SystemDrawingSize(100, 21);\x0d\ thistextBox2TabIndex = 1;\x0d\ // \x0d\ // textBox3\x0d\ // \x0d\ thistextBox3Location = new SystemDrawingPoint(448, 72);\x0d\ thistextBox3Name = "textBox3";\x0d\ thistextBox3Size = new SystemDrawingSize(88, 21);\x0d\ thistextBox3TabIndex = 2;\x0d\ // \x0d\ // comboBox1\x0d\ // \x0d\ thiscomboBox1ItemsAddRange(new object[] {\x0d\ "+",\x0d\ "-",\x0d\ "",\x0d\ "/"});\x0d\ thiscomboBox1Location = new SystemDrawingPoint(152, 72);\x0d\ thiscomboBox1Name = "comboBox1";\x0d\ thiscomboBox1Size = new SystemDrawingSize(121, 20);\x0d\ thiscomboBox1TabIndex = 3;\x0d\ thiscomboBox1SelectedIndexChanged += new SystemEventHandler(thiscomboBox1_SelectedIndexChanged);\x0d\ // \x0d\ // button1\x0d\ // \x0d\ thisbutton1Location = new SystemDrawingPoint(64, 184);\x0d\ thisbutton1Name = "button1";\x0d\ thisbutton1Size = new SystemDrawingSize(104, 32);\x0d\ thisbutton1TabIndex = 4;\x0d\ thisbutton1Text = "计算";\x0d\ thisbutton1Click += new SystemEventHandler(thisbutton1_Click);\x0d\ // \x0d\ // button2\x0d\ // \x0d\ thisbutton2Location = new SystemDrawingPoint(216, 192);\x0d\ thisbutton2Name = "button2";\x0d\ thisbutton2Size = new SystemDrawingSize(75, 23);\x0d\ thisbutton2TabIndex = 5;\x0d\ thisbutton2Text = "清除";\x0d\ thisbutton2Click += new SystemEventHandler(thisbutton2_Click);\x0d\ // \x0d\ // button3\x0d\ // \x0d\ thisbutton3Location = new SystemDrawingPoint(376, 192);\x0d\ thisbutton3Name = "button3";\x0d\ thisbutton3Size = new SystemDrawingSize(75, 23);\x0d\ thisbutton3TabIndex = 6;\x0d\ thisbutton3Text = "退出";\x0d\ thisbutton3Click += new SystemEventHandler(thisbutton3_Click);\x0d\ // \x0d\ // Form1\x0d\ // \x0d\ thisAutoScaleBaseSize = new SystemDrawingSize(6, 14);\x0d\ thisClientSize = new SystemDrawingSize(656, 366);\x0d\ thisControlsAdd(thisbutton3);\x0d\ thisControlsAdd(thisbutton2);\x0d\ thisControlsAdd(thisbutton1);\x0d\ thisControlsAdd(thiscomboBox1);\x0d\ thisControlsAdd(thistextBox3);\x0d\ thisControlsAdd(thistextBox2);\x0d\ thisControlsAdd(thistextBox1);\x0d\ thisName = "Form1";\x0d\ thisText = "Form1";\x0d\ thisResumeLayout(false);\x0d\ thisPerformLayout();\x0d\\x0d\ }\x0d\ #endregion\x0d\\x0d\ /// \x0d\ /// 应用程序的主入口点。\x0d\ /// \x0d\ [STAThread]\x0d\ static void Main() \x0d\ {\x0d\ ApplicationRun(new Form1());\x0d\ }\x0d\ public double jia(double a,double b)\x0d\ {\x0d\ return a+b;\x0d\ }\x0d\ public double jian(double a,double b)\x0d\ {\x0d\ return a-b;\x0d\ }\x0d\ public double cheng(double a,double b)\x0d\ {\x0d\ return ab;\x0d\ }\x0d\ public double chu(double a,double b)\x0d\ {\x0d\ return a/b;\x0d\ }\x0d\\x0d\private void comboBox1_SelectedIndexChanged(object sender, SystemEventArgs e)\x0d\ {\x0d\\x0d\ }\x0d\\x0d\ private void textBox1_TextChanged(object sender, SystemEventArgs e)\x0d\ {\x0d\\x0d\ }\x0d\\x0d\ private void button1_Click(object sender, SystemEventArgs e)\x0d\ {\x0d\ string i=thiscomboBox1SelectedItemToString();\x0d\\x0d\ switch(i)\x0d\ {\x0d\ \x0d\ case "+":thistextBox3Text=thisjia(doubleParse(thistextBox1Text),doubleParse(thistextBox2Text))ToString();\x0d\ \x0d\ break;\x0d\\x0d\ case "-":thistextBox3Text=thisjian(doubleParse(thistextBox1Text),doubleParse(thistextBox2Text))ToString();\x0d\ break;\x0d\ case "":thistextBox3Text=thischeng(doubleParse(thistextBox1Text),doubleParse(thistextBox2Text))ToString();\x0d\ break;\x0d\ case"/" :thistextBox3Text=thischu(doubleParse(thistextBox1Text),doubleParse(thistextBox2Text))ToString();\x0d\ break;\x0d\ }\x0d\\x0d\ }\x0d\\x0d\ private void button2_Click(object sender, SystemEventArgs e)\x0d\ {\x0d\ thistextBox1Text=null;\x0d\ thistextBox2Text=null;\x0d\ thistextBox3Text = null;\x0d\ }\x0d\\x0d\ private void button3_Click(object sender, EventArgs e)\x0d\ {\x0d\ \x0d\ //thisHide();\x0d\ ApplicationExit();\x0d\ //thisClose();\x0d\ \x0d\ }\x0d\ }\x0d\}

完全版的前后台代码

'请把下面的保存为 form1frm

VERSION 500

Begin VBForm Calculator

BorderStyle = 1 'Fixed Single

Caption = "计算器"

ClientHeight = 2970

ClientLeft = 2580

ClientTop = 1485

ClientWidth = 3270

ClipControls = 0 'False

BeginProperty Font

Name = "System"

Size = 975

Charset = 0

Weight = 700

Underline = 0 'False

Italic = 0 'False

Strikethrough = 0 'False

EndProperty

Icon = "CALCfrx":0000

LinkMode = 1 'Source

LinkTopic = "Form1"

MaxButton = 0 'False

PaletteMode = 1 'UseZOrder

ScaleHeight = 2970

ScaleWidth = 3270

WhatsThisHelp = -1 'True

Begin VBCommandButton Number

Caption = "7"

Height = 480

Index = 7

Left = 120

TabIndex = 7

Top = 600

Width = 480

End

Begin VBCommandButton Number

Caption = "8"

Height = 480

Index = 8

Left = 720

TabIndex = 8

Top = 600

Width = 480

End

Begin VBCommandButton Number

Caption = "9"

Height = 480

Index = 9

Left = 1320

TabIndex = 9

Top = 600

Width = 480

End

Begin VBCommandButton Cancel

Caption = "C"

Height = 480

Left = 2040

TabIndex = 10

Top = 600

Width = 480

End

Begin VBCommandButton CancelEntry

Caption = "CE"

Height = 480

Left = 2640

TabIndex = 11

Top = 600

Width = 480

End

Begin VBCommandButton Number

Caption = "4"

Height = 480

Index = 4

Left = 120

TabIndex = 4

Top = 1200

Width = 480

End

Begin VBCommandButton Number

Caption = "5"

Height = 480

Index = 5

Left = 720

TabIndex = 5

Top = 1200

Width = 480

End

Begin VBCommandButton Number

Caption = "6"

Height = 480

Index = 6

Left = 1320

TabIndex = 6

Top = 1200

Width = 480

End

Begin VBCommandButton Operator

Caption = "+"

Height = 480

Index = 1

Left = 2040

TabIndex = 12

Top = 1200

Width = 480

End

Begin VBCommandButton Operator

Caption = "-"

Height = 480

Index = 3

Left = 2640

TabIndex = 13

Top = 1200

Width = 480

End

Begin VBCommandButton Number

Caption = "1"

Height = 480

Index = 1

Left = 120

TabIndex = 1

Top = 1800

Width = 480

End

Begin VBCommandButton Number

Caption = "2"

Height = 480

Index = 2

Left = 720

TabIndex = 2

Top = 1800

Width = 480

End

Begin VBCommandButton Number

Caption = "3"

Height = 480

Index = 3

Left = 1320

TabIndex = 3

Top = 1800

Width = 480

End

Begin VBCommandButton Operator

Caption = "X"

Height = 480

Index = 2

Left = 2040

TabIndex = 14

Top = 1800

Width = 480

End

Begin VBCommandButton Operator

Caption = "/"

Height = 480

Index = 0

Left = 2640

TabIndex = 15

Top = 1800

Width = 480

End

Begin VBCommandButton Number

Caption = "0"

Height = 480

Index = 0

Left = 120

TabIndex = 0

Top = 2400

Width = 1080

End

Begin VBCommandButton Decimal

Caption = ""

Height = 480

Left = 1320

TabIndex = 18

Top = 2400

Width = 480

End

Begin VBCommandButton Operator

Caption = "="

Height = 480

Index = 4

Left = 2040

TabIndex = 16

Top = 2400

Width = 480

End

Begin VBCommandButton Percent

Caption = "%"

Height = 480

Left = 2640

TabIndex = 17

Top = 2400

Width = 480

End

Begin VBLabel Readout

Alignment = 1 'Right Justify

BackColor = &H0000FFFF&

BorderStyle = 1 'Fixed Single

Caption = "0"

BeginProperty Font

Name = "MS Sans Serif"

Size = 12

Charset = 0

Weight = 700

Underline = 0 'False

Italic = 0 'False

Strikethrough = 0 'False

EndProperty

ForeColor = &H00000000&

Height = 375

Left = 120

TabIndex = 19

Top = 105

Width = 3000

End

End

Attribute VB_Name = "Calculator"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

' --------------------------------------------------------------------------

' 版权所有 (C) 1994 Microsoft Corporation

'

' 您可以免费以任何方式使用、修改、复制并分发您认为有用的

' 示例应用程序文件 (或任何修改过的版本)。Microsoft 对任何

' 示例应用程序文件不做任何保证,不负任何责任和义务。

' --------------------------------------------------------------------------

Option Explicit

Dim Op1, Op2 ' 前面输入的 *** 作数

Dim DecimalFlag As Integer ' 小数点仍然存在吗?

Dim NumOps As Integer ' *** 作数个数

Dim LastInput ' 指示上一次按键事件的类型

Dim OpFlag ' 指示未完成的 *** 作

Dim TempReadout

' C (取消) 按钮的 Click 事件过程

' 重新设置显示并初始化变量

Private Sub Cancel_Click()

Readout = Format(0, "0")

Op1 = 0

Op2 = 0

Form_Load

End Sub

' CE (取消输入) 按钮的 Click 事件过程

Private Sub CancelEntry_Click()

Readout = Format(0, "0")

DecimalFlag = False

LastInput = "CE"

End Sub

' 小数点 () 按钮的 Click 事件过程

' 如果上一次按键为运算符,初始化 readout 为 "0";

' 否则显示时追加一个小数点

Private Sub Decimal_Click()

If LastInput = "NEG" Then

Readout = Format(0, "-0")

ElseIf LastInput <> "NUMS" Then

Readout = Format(0, "0")

End If

DecimalFlag = True

LastInput = "NUMS"

End Sub

' 窗体的初始化过程

' 设置所有变量为其初始值

Private Sub Form_Load()

DecimalFlag = False

NumOps = 0

LastInput = "NONE"

OpFlag = " "

Readout = Format(0, "0")

'DecimalCaption = Format(0, "")

End Sub

' 数字键 (0-9) 的 Click 事件过程

' 向显示中的数追加新数

Private Sub Number_Click(Index As Integer)

If LastInput <> "NUMS" Then

Readout = Format(0, "")

DecimalFlag = False

End If

If DecimalFlag Then

Readout = Readout + Number(Index)Caption

Else

Readout = Left(Readout, InStr(Readout, Format(0, "")) - 1) + Number(Index)Caption + Format(0, "")

End If

If LastInput = "NEG" Then Readout = "-" & Readout

LastInput = "NUMS"

End Sub

' 运算符 (+, -, x, /, =) 的 Click 事件过程

' 如果接下来的按键是数字键,增加 NumOps。

' 如果有一个 *** 作数,则设置 Op1。

' 如果有两个 *** 作数,则将 Op1 设置为 Op1 与

' 当前输入字符串的运算结果,并显示结果

Private Sub Operator_Click(Index As Integer)

TempReadout = Readout

If LastInput = "NUMS" Then

NumOps = NumOps + 1

End If

Select Case NumOps

Case 0

If Operator(Index)Caption = "-" And LastInput <> "NEG" Then

Readout = "-" & Readout

LastInput = "NEG"

End If

Case 1

Op1 = Readout

If Operator(Index)Caption = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then

Readout = "-"

LastInput = "NEG"

End If

Case 2

Op2 = TempReadout

Select Case OpFlag

Case "+"

Op1 = CDbl(Op1) + CDbl(Op2)

Case "-"

Op1 = CDbl(Op1) - CDbl(Op2)

Case "X"

Op1 = CDbl(Op1) CDbl(Op2)

Case "/"

If Op2 = 0 Then

MsgBox "除数不能为 0", 48, "计算器"

Else

Op1 = CDbl(Op1) / CDbl(Op2)

End If

Case "="

Op1 = CDbl(Op2)

Case "%"

Op1 = CDbl(Op1) CDbl(Op2)

End Select

Readout = Op1

NumOps = 1

End Select

If LastInput <> "NEG" Then

LastInput = "OPS"

OpFlag = Operator(Index)Caption

End If

End Sub

' 百分比键 (%) 的 Click 事件过程

' 计算并显示第一个 *** 作数的百分数

Private Sub Percent_Click()

Readout = Readout / 100

LastInput = "Ops"

OpFlag = "%"

NumOps = NumOps + 1

DecimalFlag = True

End Sub

Option Explicit

Dim FirstNumber, NumberBuffer As Double'定义数据类型

Dim chr As String

Dim ScaleCodeState As Boolean

Dim ScaleCode As Integer

Dim ScaleSymbol(0 To 7) As String '上面这些DIM都是定义数据类型

Private Sub Init()'==sub过程,实际功能就是清零。把label、FirstNumber、等都初始化

Label1Caption = "0"

FirstNumber = 0

ScaleCode = 0

ScaleCodeState = False

Label2Caption = ""

End Sub        '==sub过程结束

Private Sub ClearAll_Click() '点击ClearAll按钮

Call Init'执行init过程,就是清零

End Sub

Private Sub Form_Load()'程序启动

Call Init'先清零,下面分别赋值加减乘除

ScaleSymbol(0) = "+"

ScaleSymbol(1) = "-"

ScaleSymbol(2) = ""

ScaleSymbol(3) = "/"

End Sub

Private Sub NumberKey_Click(Index As Integer)'点击NumberKey按钮,NumberKey是数组控件

chr = Val(Index)

If Left(Label1Caption, 1) = "0" And Mid(Label1Caption, 2, 1) <> "" Then Label1Caption = Right(Label1Caption, Len(Label1Caption) - 1)

'如果label1的第一个字符是0,并且第二个字符不是,则label1去掉第一个0。这个功能是防止输入了009999这样的数,就自动变为09999

If Len(Label1Caption) < 20 Then '判断输入的数字长度小于20

    If ScaleCodeState = True Then

        ScaleCodeState = False

        Label1Caption = ""

    End If

    Label1Caption = Label1Caption + chr

    NumberBuffer = Val(Label1Caption)

End If

End Sub

Private Sub ScaleKey_Click(Index As Integer)'点加减乘除

ScaleCode = Index

FirstNumber = NumberBuffer

ScaleCodeState = True

Label2Caption = ScaleSymbol(Index)

Label1Caption = "0"

End Sub

Private Sub Equal_Click()'开始计算

Select Case ScaleCode

Case 0'加

NumberBuffer = FirstNumber + NumberBuffer

Case 1'减

NumberBuffer = FirstNumber - NumberBuffer

Case 2'乘

NumberBuffer = FirstNumber  NumberBuffer

Case 3'除

NumberBuffer = FirstNumber / NumberBuffer

End Select

Label1Caption = NumberBuffer'显示结果

FirstNumber = NumberBuffer

ScaleCodeState = True

Label2Caption = ""

End Sub

#include<stdioh>

#include<stdlibh>

#include<stringh>

#include<conioh>

#include<mathh>

int resultprocess(char mexp[],double result);

int tokenprocess(char mexp[],double shuzhi[],char signs[]);

double resultadd(double shuzhi[],char signs[],int sp);

void main()

{

char mexp[100];

double result=0;

printf("Please input the maths expression:\n\nmexp=");

gets(mexp);

if(resultprocess(mexp,&result))

printf("\nThe result of the maths expression is:\n\nresult=%lf\n",result);

else

printf("\nThe maths expression is wrong,can't be processed!");

getch();

}

int resultprocess(char mexp[],double result)

{

char signs[100];

double shuzhi[100];

int sp;

sp=tokenprocess(mexp,shuzhi,signs);

if(sp>0)

{

result=resultadd(shuzhi,signs,sp);

return 1;

}

else

return 0;

}

int tokenprocess(char mexp[],double shuzhi[],char signs[])

{

char strtemp[100],chartemp;

int shuzhiflag=0,spaceflag=0,dotflag=0,sp=0,i;

signs[0]='+';

for(i=0;mexp[i]!='\0';i++)

{

chartemp=mexp[i];

if(chartemp=='+'||chartemp=='-'||chartemp==''||chartemp=='/'||chartemp=='^')

{

if(shuzhiflag==0)

{

if(chartemp=='-'&&sp==0)

{

strtemp[shuzhiflag]=chartemp;

strtemp[shuzhiflag+1]='\0';

shuzhiflag++;

}

else

return 0;

}

else

{

shuzhi[sp]=atof(strtemp);

sp++;

shuzhiflag=0;

spaceflag=0;

dotflag=0;

signs[sp]=chartemp;

}

}

else

if(chartemp>='0'&&chartemp<='9')

{

if(spaceflag==2)

return 0;

else

{

strtemp[shuzhiflag]=chartemp;

strtemp[shuzhiflag+1]='\0';

shuzhiflag++;

}

}

else

if(chartemp=='')

{

if(dotflag==1)

return 0;

else

if(dotflag==0&&shuzhiflag==0)

return 0;

else

{

dotflag=1;

strtemp[shuzhiflag]=chartemp;

strtemp[shuzhiflag+1]='\0';

shuzhiflag++;

}

}

else

if(chartemp==' ')

{

if(shuzhiflag>0)

spaceflag=2;

else

spaceflag=1;

}

else

return 0;

}

if(shuzhiflag>0)

{

shuzhi[sp]=atof(strtemp);

sp++;

return sp;

}

else

return 0;

}

double resultadd(double shuzhi[],char signs[],int sp)

{

int i;

double result=0;

for(i=1;i<sp;i++)

if(signs[i]=='^')

{

shuzhi[i]=pow(shuzhi[i-1],shuzhi[i]);

signs[i]='';

shuzhi[i-1]=1;

}

for(i=1;i<sp;i++)

if(signs[i]==''||signs[i]=='/')

{

if(signs[i]=='')

shuzhi[i]=shuzhi[i-1]shuzhi[i];

else

shuzhi[i]=shuzhi[i-1]/shuzhi[i];

signs[i]=signs[i-1];

shuzhi[i-1]=0;

}

for(i=0;i<sp;i++)

{

if(signs[i]=='+')

result=result+shuzhi[i];

else

result=result-shuzhi[i];

}

return result;

}

#include<stdioh>

#include<windowsh>

#include<mathh>

#define p 31415926

#define r p/180 //r=p/180,p=314,p/180是求的1弧度,下面sin(里面要求的是弧度),sin(30弧度)=05。 void main()

{

float i,j,k;

int l,m,n,a[10];

char cmd;

LOOP:

system("cls");

printf("\n");

printf("小寒计算器\n");

printf("\n");

printf("\n\n本计算器提供+、-、、/四种运算。\n");

printf("p-代表圆周率pai。\n");

printf("a-代表十进制转换为二进制。\n");

printf("b-代表十进制转换为八进制。\n");

printf("c-代表十进制转换为十六进制。\n");

printf("d-代表该数值开方。\n");

printf("e-代表该数值开立方。\n");

printf("f-代表求几次方。\n");

printf("S-代表sin。\n");

printf("C-代表cos。\n");

printf("T-代表tan。\n");

printf("\n\n请输入要计算的数字和运算符号,输入“#”时,结束;输入“!”时复位。\n");

scanf("%f",&k);

while((cmd=getchar())!='#')

{

if(i!=0)

switch(cmd)

{

case '+': scanf("%f",&i);

k=k+i;

printf("=%52f",k);

break; case '-': scanf("%f",&i);

k=k-i;

printf("=%52f",k);

break; case '': scanf("%f",&i);

k=ki;

printf("=%52f",k);

break; case '/': scanf("%f",&i);

k=k/i;

printf("=%52f",k);

break;

case 'p': k=kp;

printf("%64f",k);

break; case 'f': printf("请输入要求该数字的几次方:");

scanf("%d",&n);

i=k;

for(m=0;m<n-1;m++)

k=ki;

printf("%52f",k);

break; case 'a': printf("转换成二进制\n");

m=0;

while((int)k>0)

{

l=k;

k=k/2;

l=l%2;

a[m]=l;

m++;

}

for(n=m-1;n>=0;n--)

printf("%d",a[n]);

break; case 'b': printf("转换成八进制\n");

m=0;

while((int)k>0)

{

l=k;

k=k/8;

l=l%8;

a[m]=l;

m++;

}

for(n=m-1;n>=0;n--)

printf("%d",a[n]);

break;

case 'c': printf("转换成十六进制\n");

m=0;

while((int)k>0)

{

l=k;

k=k/16;

l=l%16;

a[m]=l;

m++;

}

for(n=m-1;n>=0;n--)

{

if(a[n]==10)

{ printf("A");continue;}

else if(a[n]==11)

{ printf("B");continue;}

else if(a[n]==12)

{ printf("C");continue;}

else if(a[n]==13)

{ printf("D");continue;}

else if(a[n]==14)

{ printf("E");continue;}

else if(a[n]==15)

{ printf("F");continue;} printf("%d",a[n]);

}

break;

case 'e': printf("该数值开立方得\n");

i=pow(k,10/3);

printf("%52f",i );

break;

case 'd': printf("该数值开方得\n");

i=k/2;

j=sqrt(k);

printf("%52f",j);

break; case 'S': k=kr;

i=sin(k);

printf("%52f",i);

break;

case 'C': k=kr;

i=cos(k);

printf("%52f",i);

break; case 'T': k=kr;

i=tan(k);

printf("%52f",i);

break; case '!': goto LOOP;

}

}

}

以上就是关于如何用c#编写计算器代码(只要加减乘除)全部的内容,包括:如何用c#编写计算器代码(只要加减乘除)、用VB编写计算器的源程序代码、VB 计算器程序代码解析,以下是代码,要求详细,新手VB勿喷等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9308760.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存