當前位置:首頁 » 編程軟體 » 簡易計算器反編譯

簡易計算器反編譯

發布時間: 2022-11-03 21:26:49

A. 怎麼用C++編譯一個簡單的計算器

我借鑒了別人的某計算器,因為你沒有說多簡易...我就找了個差不多的...
/*
程序名稱:表達式計算器
編譯環境:Microsoft Visual C++ 6.0
作者:吉林大學 計算機科學與技術學院 2006 羅泗勇
時間:200801
*/

/*
說明:
採用樹形結構處理表達式,按優先順序運算結果,一個加,減,乘,除或數值為一個節點
優先順序如下:
函數:4
括弧:3
乘除:2
加減:1
*/

#include <windows.h>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;

const char NUM[]={'0','1','2','3','4','5','6','7','8','9','.'};
const char OPERATION[]={'+','-','*','/'};
const double PI=3.14159265358979;
const double EE=2.71828182818281;

class Fun //處理系統數學函數的類
{
public:
Fun(string o,int t,double l=0.0,double r=0.0):op(o),type(t),lvalue(l),rvalue(r){}
static string FUN[];
double calc();
private:
int type; //666 0 1 sin90 2 3! 3 3C2
string op; //函數類型
double lvalue; //函數左邊的值
double rvalue; //函數右邊的值
static int FunNum;
};

int Fun::FunNum=8;
string Fun::FUN[]={"!","sin","cos","tan","log","ln","C","A","^"};
/*
函數說明:
1:log是以10為底的工程對數
2:ln 是以e為底的自然對數
3:C 計算組合數 輸入規則 如計算 3取2的組合 輸入表達式 3C2
4:A 計算排列數 輸入規則 如計算 3取2的排列 輸入表達式 3A2
5:! 計算階乘
6:^ x的y次方 輸入 x^y
*/

int factorial(int n) //階乘函數
{
int i,s=1;
for(i=1;i<=n;i++)
s*=i;
return s;
}

int C(int a,int b)
{
return factorial(a)/(factorial(b)*factorial(a-b));
}

int A(int a,int b)
{
return factorial(a)/factorial(b);
}

double Fun::calc() //計算系統函數的值
{
if(type==0)
return lvalue;
else
{
if(op=="!")
return factorial(lvalue);
if(op=="sin")
return sin(rvalue/180*PI);
if(op=="cos")
return cos(rvalue/180*PI);
if(op=="tan")
return tan(rvalue/180*PI);
if(op=="log")
return log10(rvalue);
if(op=="ln")
return log10(rvalue)/log10(EE);
if(op=="C")
return C(lvalue,rvalue);
if(op=="A")
return A(lvalue,rvalue);
if(op=="^")
return pow(lvalue,rvalue);
else
{
string err="暫時沒有函數"+op;
MessageBox(NULL,err.c_str(),"錯誤",MB_OK);
return 0;
}
}
}

struct Unit //雙向鏈表保存運算單元
{
Unit(int p,char o,string c,double v,int t,Unit * pr=NULL,Unit * n=NULL)
:PRI(p),Operation(o),Code(c),value(v),Type(t),Pre(pr),Next(n){}
int PRI; //優先順序

char Operation; //操作符
string Code; //原始代碼
double value; //數據

int Type; //類型 操作符0 數據1 函數2
Unit * Pre; //構成雙向鏈表
Unit * Next;
};

class Node //表達式樹狀結構的節點
{
public:
Node(char o,int p,int e=1,double v=0,Node * ph=NULL,Node * pl=NULL,Node * pr=NULL)
:Operation(o),PRI(p),Expression(e),value(v),Head(ph),Left(pl),Right(pr){}
Node * Head; //節點的根,左樹枝,右樹枝
Node * Left;
Node * Right;
double GetValue();
char GetOperation() const {return Operation;}
int GetPri() const {return PRI;}
int IsExp() const {return Expression;}
private:
char Operation; //操作符
int PRI; //優先順序
int Expression; //記錄該節點是否是表達式0 1
double value; //該節點的值
};

double Node::GetValue() //運算該節點的值
{
if(IsExp()) //該節點的值還未算出來
{
double lvalue,rvalue;
lvalue=Left->GetValue();
rvalue=Right->GetValue();
Expression=0;
char op=GetOperation();
switch(op)
{
case '+':
return lvalue+rvalue;
case '-':
return lvalue-rvalue;
case '*':
return lvalue*rvalue;
case '/':
return lvalue/rvalue;
default:
return 0;
}
}
else
return value;
}

bool Isnum(char c)
{
for(int i=0;i<sizeof(NUM);i++)
{
if(c==NUM[i])
return true;
}
return false;
}

bool Isoperation(char c)
{
for(int i=0;i<sizeof(OPERATION);i++)
{
if(c==OPERATION[i])
return true;
}
return false;
}

Unit * Analyse(string exp) //分析表達式並生成鏈表
{
int pri=0; //當前優先順序
int stat=-1; //當前的讀入狀態 括弧 0 數據 1 運算符 2
Unit * head=NULL,* p=NULL;
int i=0,explen;
explen=exp.size();
for(i=0;i<explen;i++)
{
char c=exp.at(i);
if(c=='(')
{
pri+=3;
stat=0;
}
else if(c==')')
{
pri-=3;
stat=0;
}
else if(Isoperation(c)) //操作符不會出現在表達式開頭
{
Unit * temp=p;
int add_pri; //自身增加的優先順序
if(c=='+' || c=='-')
add_pri=1;
else
add_pri=2;
p->Next=new Unit(pri+add_pri,c," ",0,0);
p=p->Next;
p->Pre=temp;
}
else //其他的當做函數處理
{
string function="";
while(i<explen && (c=exp.at(i),! Isoperation(c)) && c!=')')
{
function+=c;
i++;
}
i--;

if(head==NULL)
{
p=new Unit(pri,' ',function,0,2);
head=p;
}
else
{
Unit * temp=p;
p->Next=new Unit(pri,' ',function,0,2);
p=p->Next;
p->Pre=temp;
}
}
}
return head;
}

Unit * Calc(Unit * head) //計算雙向鏈表基本單元的值
{
Unit * p=head;
while(p!=NULL)
{
if(p->Type!=0) //非操作符
{
string temp=p->Code;
string op;
double lvalue=0,rvalue=0;
int l_point=0,r_point=0;
int i=0,type=0;
char ch;
while(i<temp.size() && (ch=temp.at(i),Isnum(ch)))
{
if(ch=='.')
{
l_point++;
i++;
continue;
}
if(! l_point)
lvalue*=10;
lvalue+=(ch-'0')*pow(10,-l_point);
i++;
if(l_point)
l_point++;
}
while(i<temp.size() && (ch=temp.at(i),! Isnum(ch)))
{
op+=ch;
type=1;
i++;
}
while(i<temp.size() && (ch=temp.at(i),Isnum(ch)))
{
if(ch=='.')
{
r_point++;
i++;
continue;
}
if(! r_point)
rvalue*=10;
rvalue+=(ch-'0')*pow(10,-r_point);
i++;
if(r_point)
r_point++;
}
Fun * f=new Fun(op,type,lvalue,rvalue);
p->value=f->calc();
}
p=p->Next;
}
return head;
}

Node * Tree(Unit * head) //生成表達式樹
{
Node * root=NULL,* proot=NULL,* pbranch=NULL;
Unit * p=head;
int now_pri; //當前優先順序
bool hadop=false;
while(p!=NULL)
{
if(p->Type==0) //如果是一個操作符
{
hadop=true;
if(root==NULL)
{
proot=new Node(p->Operation,p->PRI,1);
root=proot;
pbranch=root;
now_pri=p->PRI;
proot->Left=new Node(' ',0,0,p->Pre->value);
proot->Right=new Node(' ',0,0,p->Next->value);
}
else
{
if(p->PRI<=now_pri) //優先順序低於當前優先順序,樹根方向 //最初寫的 if(p->PRI<now_pri),9/3/3=9,錯的
{
proot=new Node(p->Operation,p->PRI,1); //新的樹根
proot->Left=root; //根的變換
proot->Right=new Node(' ',0,0,p->Next->value);
root=proot;

pbranch=proot; //右樹枝的變換
//pbranch->Right=new Node(' ',0,0,p->Pre->value); //樹枝右邊取值
}
else
{
Node * temp;
temp=new Node(p->Operation,p->PRI,1);

pbranch->Right=temp;
temp->Head=pbranch;

pbranch=pbranch->Right;
pbranch->Left=new Node(' ',0,0,p->Pre->value);
pbranch->Right=new Node(' ',0,0,p->Next->value);
}
now_pri=p->PRI;
}
}
p=p->Next;
}
if(! hadop)
root=new Node(' ',0,0,head->value);
return root;
}

int main()
{
string exp;

//ifstream infile("test.txt",ios::in);
while(! getline(cin,exp).eof())
{
if(exp=="")
continue;
Unit * h=Analyse(exp);
h=Calc(h);
Node * root=Tree(h);
cout<<exp<<"="<<root->GetValue()<<endl;
}
return 0;
}

B. HELP!DEV-C++反編譯人品計算器!

editable=ture??? 你寫錯了吧?應該是 editable=true;

C. 用javaScript做一個簡易的計算器

我剛學javaScript做一計算器,請看看!多多交流!~~``

<html>
<head>
<title>計算器</title>
</head>
<body bgcolor="#33FF99" onload="FKeyPad.ReadOut.focus();FKeyPad.ReadOut.select();">
<FORM name="Keypad" action="">
<TABLE align="center">
<B>
<TABLE align="center" border=3 width=60 height=80 cellpadding=2 cellspacing=5 borderlight="#008080">
<tr align="center">
<td bordercolor="#FF33CC" bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933" colspan=10 align=center>網頁計算器</td>
</tr>
<tr align="center">
<td bordercolor="#FF33CC" bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933" colspan=10 align=right><input name="ReadOut" type="Text" onkeypress="CheckOut()" size=40 value="0"
width=100%></td>
</tr>
<tr align="center">
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnsin" type="Button" value=" sin " onclick="useFun ('sin')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btncos" type="Button" value=" cos " onclick="useFun ('cos')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnOne" type="Button" value=" 1 " onclick="NumPressed(1)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnTwo" type="Button" value=" 2 " onclick="NumPressed(2)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnThree" type="Button" value=" 3 " onclick="NumPressed(3)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnPlus" type="Button" value=" + " onclick="Operation('+')"> </td>
</tr>
<tr align="center">
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnasin" type="Button" value=" asin " onclick="useFun ('asin')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnacos" type="Button" value=" acos " onclick="useFun ('acos')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnFour" type="Button" value=" 4 " onclick="NumPressed(4)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnFive" type="Button" value=" 5 " onclick="NumPressed(5)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnSix" type="Button" value=" 6 " onclick="NumPressed(6)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnMinus" type="Button" value=" - " onclick="Operation('-')"></td>
</tr>
<tr align="center">
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btntan" type="Button" value=" tan " onclick="useFun ('tan')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnatan" type="Button" value=" atan " onclick="useFun ('atan')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnSeven" type="Button" value=" 7 " onclick="NumPressed(7)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnEight" type="Button" value=" 8 " onclick="NumPressed(8)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnNine" type="Button" value=" 9 " onclick="NumPressed(9)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnMultiply" type="Button" value=" * " onclick="Operation('*')"></td>
</tr>
<tr align="center">
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnlog" type="Button" value=" log " onclick="useFun ('log')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnexp" type="Button" value=" exp " onclick="useFun ('exp')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnZero" type="Button" value=" 0 " onclick="NumPressed(0)"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnDecimal" type="Button" value=" . " onclick="Decimal()"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnNeg" type="Button" value=" +/- " onclick="Neg()"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnDivide" type="Button" value=" / " onclick="Operation('/')"></td>
</tr>
<tr align="center">
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnsqrt" type="Button" value=" sqrt " onclick="useFun ('sqrt')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnOx" type="Button" value=" 1/x " onclick="useFun ('1/x')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnXt" type="Button" value=" x^2 " onclick="useFun ('x^2')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnXthr" type="Button" value=" x^3 " onclick="useFun ('x^3')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnpi" type="Button" value=" pi " onclick=FKeyPad.ReadOut.value=Math.PI></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnEquals" type="Button" value=" = " onclick="Operation('=')"></td>
</tr>
<tr align="center">
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnDivide" type="Button" value=" N! " onclick="ni ()"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnDivide" type="Button" value=" pow " onclick="Operation('pow')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnDivide" type="Button" value=" E " onclick=FKeyPad.ReadOut.value=Math.E></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnClear" type="Button" value=" C " onclick="Clear()"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnClearEntry" type="Button" value=" CE " onclick="ClearEntry()"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnReturn" type="Button" value="返 回" onclick="goReturn()"></td>
</tr>
<tr align="center">
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnmod" type="Button" value=" MOD " onclick="Operation('MOD')"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnDivide" type="Button" value=" INT" onclick=FKeyPad.ReadOut.value=parseInt(FKeyPad.ReadOut.value,10)></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnmod" type="Button" value=" HEX " onclick="hexchange ()"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnmod" type="Button" value=" OCT " onclick="octchange ()"></td>
<td bordercolordark="#cc0066" bordercolor="#FF9966" bordercolorlight="#CC9933"><input name="btnmod" type="Button" value=" BIN " onclick="binchange ()"></td>
</tr>
</TABLE>
</TABLE>
</B>
</FORM>
</CENTER>
<font face="Verdana, Arial, Helvetica" size=2>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var FKeyPad = document.forms['Keypad'];
var Accum = "0";
var FlagNewNum = false;
var PendingOp = "";
function longCount(str1,str2,type)
{
var comma1 = 0;
if (str1.indexOf(".")!=-1)
{
str1 = str1.replace(/0*$/,"");
comma1 = str1.length - str1.indexOf(".")-1;
}
var comma2 = 0;
if (str2.indexOf(".")!=-1)
{
str2 = str2.replace(/0*$/,"");
comma2 = str2.length - str2.indexOf(".")-1;
}
str1 = str1.replace(/\./,"");
str2 = str2.replace(/\./,"");
var value,comma;
if (type!="*")
{
if (comma1>comma2)
{
for (var i=0;i<comma1-comma2;i++) str2 += "0";
comma = (type=="/")?0:comma1;
}else
{
for (var i=0;i<comma2-comma1;i++) str1 += "0";
comma = (type=="/")?0:comma2;
}
}else
{
comma = comma1 + comma2;
}
if (type=="+")
{
value = parseInt(str1,10) + parseInt(str2,10);
}else if (type=="-")
{
value = parseInt(str1,10) - parseInt(str2,10);
}else if (type=="*")
{
value = parseInt(str1,10) * parseInt(str2,10);
}else if (type=="/")
{
value = parseInt(str1,10) / parseInt(str2,10);
}
else if (type=="MOD")
value = parseInt(str1,10) % parseInt(str2,10);
else if (type=="pow")
{
var a,b,s=1;
a=parseInt(str1,10);
b=parseInt(str2,10);
for(var i=1;i<=b;i++)
s=s*a;
value=parseInt(s,10);
}
value = String(value);
if (comma>0) value = value.substring(0,value.length-comma)+"."+value.substring(value.length- comma,value.length);
if (value.indexOf(".")!=-1)
value = value.replace(/0*$/,"");
return value;
}
function NumPressed (Num) {
if (FlagNewNum)
{
FKeyPad.ReadOut.value = Num;
FlagNewNum = false;
}
else
{
if (FKeyPad.ReadOut.value == "0")
FKeyPad.ReadOut.value = Num;
else
FKeyPad.ReadOut.value += Num;
}
}
function Operation (Op)
{
var Readout = FKeyPad.ReadOut.value;
if (FlagNewNum && PendingOp != "=");
else
{
FlagNewNum = true;
if ( '+' == PendingOp || '-' == PendingOp || '/' == PendingOp || '*' == PendingOp||'MOD'==PendingOp||'pow'==PendingOp)
Accum = longCount(Accum,Readout,PendingOp);
else
Accum = Readout;
FKeyPad.ReadOut.value = Accum;
PendingOp = Op;
FKeyPad.ReadOut.focus();
FKeyPad.ReadOut.select();
}
}
function useFun (st)
{
switch(st)
{
case "sin":
FKeyPad.ReadOut.value=Math.sin(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "cos":
FKeyPad.ReadOut.value=Math.cos(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "asin":
FKeyPad.ReadOut.value=Math.asin(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "acos":
FKeyPad.ReadOut.value=Math.acos(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "tan":
FKeyPad.ReadOut.value=Math.tan(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "atan":
FKeyPad.ReadOut.value=Math.atan(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "log":
FKeyPad.ReadOut.value=Math.log(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "exp":
FKeyPad.ReadOut.value=Math.exp(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "sqrt":
FKeyPad.ReadOut.value=Math.sqrt(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "1/x":
FKeyPad.ReadOut.value=1/FKeyPad.ReadOut.value;
FlagNewNum=true;
break;
case "x^2":
FKeyPad.ReadOut.value=parseFloat(FKeyPad.ReadOut.value)*parseFloat(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;
case "x^3":
FKeyPad.ReadOut.value=parseFloat(FKeyPad.ReadOut.value)*parseFloat(FKeyPad.ReadOut.value)*parseFloat(FKeyPad.ReadOut.value);
FlagNewNum=true;
break;

}

}
function hexchange ()
{
var hex,dec;
dec = parseFloat(FKeyPad.ReadOut.value);
hex = dec.toString(16);
window.alert("該十進制數轉成十六進制數為:"+ hex);
}
function octchange ()
{
var oct,dec;
dec = parseFloat(FKeyPad.ReadOut.value);
oct = dec.toString(8);
window.alert("該十進制數轉成八進制數為:"+ oct);
}
function binchange ()
{
var bin,dec;
dec = parseFloat(FKeyPad.ReadOut.value);
bin = dec.toString(2);
window.alert("該十進制數轉成二進制數為:"+ bin);
}
function ni ()
{var y,k=1;
y=parseFloat(FKeyPad.ReadOut.value);
for(var x=1;x<=y;x++)
k=k*x;
FKeyPad.ReadOut.value=k;
}
function Decimal ()
{
var curReadOut = FKeyPad.ReadOut.value;
if (FlagNewNum)
{
curReadOut = "0.";
FlagNewNum = false;
}
else
{
if (curReadOut.indexOf(".") == -1)
curReadOut += ".";
}
FKeyPad.ReadOut.value = curReadOut;
}
function ClearEntry ()
{
FKeyPad.ReadOut.value = "0";
FlagNewNum = true;
}
function Clear ()
{
Accum = "0";
PendingOp = "";
ClearEntry();
}
function Neg ()
{
window.alert(FKeyPad.ReadOut.value);
FKeyPad.ReadOut.value = longCount(FKeyPad.ReadOut.value,"-1","*");
}

function goReturn()
{
top.returnValue = FKeyPad.ReadOut.value;
self.close();
}
function CheckOut()
{
var keyCode = window.event.keyCode;
if (keyCode>=48 && keyCode<=57)
{
if (FlagNewNum)
{
FKeyPad.ReadOut.value = "";
FlagNewNum = false;
}
return true;
}else if (keyCode==43 || keyCode==45 || keyCode==42 || keyCode==47 || keyCode==61) {
Operation(String.fromCharCode(keyCode));
}else if (keyCode==46) {
if (FKeyPad.ReadOut.value.indexOf(".") == -1)
return true;
}else if (keyCode==27) goReturn();
window.event.returnValue = false;
return false;
}
// End -->
</SCRIPT>
</body>
</html>

D. c語言TC版,簡 易 計 算 器,行數不太夠,高手幫改下。

想不到還有要求程序行數越多越好的
我看這老師標准有問題,或者你誤解了老師的意思。
老師是希望你的程序功能達到一定的規模,而不是同樣的功能要擴充代碼量。
同樣的功能,寫代碼量越少越好,寫得少錯得少
能不寫代碼就實現功能更好。
你誤解了高手的標准。
其實把代碼寫少是最難的,
比如你寫一百個功能,如果80行就寫出來了,那就是真正的牛人了。

E. MFC編寫計算器具體步驟 方法 代碼,拜託高手急用!

1、首先打開VS2013,新建一個VC++ MFC項目,命名為 gongzi。

F. 簡易計算器代碼

http://post..com/f?kz=209715785 我的計算器 Option Explicit Dim FocusText As VB.TextBox Dim pd As Boolean Dim x As Double Dim y As Double Dim ch As Integer Private Sub Command1_Click(Index As Integer) On Error Resume Next FocusText.SetFocus If Index SendKeys Index ElseIf Index = 10 Then ch = Index - 10 x = Val(Text1.Text) Text1.Text = "" ElseIf Index = 14 Then y = Val(Text1.Text) Select Case ch Case 0 Text1.Text = x + y Case 1 Text1.Text = x - y Case 2 Text1.Text = x * y Case 3 Text1.Text = x / y End Select ElseIf Index = 15 Then FocusText.SetFocus SendKeys "{BS}" ElseIf Index = 16 Then FocusText.SetFocus SendKeys "." End If End Sub '防止輸入多個小數點以及出數字外的其他字元 Private Sub Text1_KeyPress(KeyAscii As Integer) If (KeyAscii 57) And KeyAscii 46 And KeyAscii 8 Then KeyAscii = 0 End If If pd = True And KeyAscii = 46 Then KeyAscii = 0 End If If pd = False And KeyAscii = 46 Then pd = True KeyAscii = 46 End If End Sub '防止 Ctrl + v 粘貼 Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyV And Shift = vbCtrlMask Then Text1.Enabled = False Clipboard.Clear Text1.Enabled = True End If End Sub '防止右鍵粘貼 Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) If Button = vbRightButton Then Text1.Enabled = False Clipboard.Clear Text1.Enabled = True End If End Sub Private Sub Text1_LostFocus() Set FocusText = Text1 End Sub 界面如下 0為Command1(0)1為Command1(1)依次類推 ←為Command1(15) 小數點為Command1(16) 貼子相關圖片: 界面可以到



G. c語言設計一個簡單的計算器程序

#include<stdio.h>//計算器

voidmenu()//自定義的菜單界面

printf("--------------------\n");

printf("請輸入你的選擇\n");

printf("1.+\n");

printf("2.-\n");

printf("3.*\n");

printf("4./\n");

printf("--------------------\n");

intmain()

inti=0;

intj=0;

intnum=0;//計算結果存放在nun

intselect=0;//選擇的選項存放在select

do//do-while先執行再判斷循環條件,即可實現重復計算功能

menu();//列印出菜單界面

scanf("%d",&select);//輸入你的選項

printf("請輸入計算值:");

scanf("%d%d",&i,&j);//輸入要計算的數值

switch(select)

case1:

printf("%d+%d=%d\n",i,j,num=i+j);//實現加法功能

break;

case2:

printf("%d-%d=%d\n",i,j,num=i-j);//實現減法功能

break;

case3:

printf("%d*%d=%d\n",i,j,num=i*j);//實現乘法功能

break;

case4:

printf("%d-%d=%d\n",i,j,num=i/j);//實現除法功能

break;

default:

printf("輸入有誤重新選擇");

break;

}while(select);

return0;

運行結果:

(7)簡易計算器反編譯擴展閱讀:

return表示把程序流程從被調函數轉向主調函數並把表達式的值帶回主調函數,實現函數值的返回,返回時可附帶一個返回值,由return後面的參數指定。

return通常是必要的,因為函數調用的時候計算結果通常是通過返回值帶出的。如果函數執行不需要返回計算結果,也經常需要返回一個狀態碼來表示函數執行的順利與否(-1和0就是最常用的狀態碼),主調函數可以通過返回值判斷被調函數的執行情況。

H. 如何用java做一個計算器,請各位伸出援助之手,小女子感激不盡。

package lab5;
public class Calculate {

double op1 = 0;

double op2 = 0;

double rgst = 0;

double result = 0;

String curStr = "";

Operator op = Operator.ADD;

CalculatorView calView = null;

public Calculate(CalculatorView view) {
op1 = 0;
op2 = 0;
curStr = "0";
rgst = 0;
op = Operator.ADD;
calView = view;
}

public void clear() {
op1 = 0;
op2 = 0;
curStr = "0.0";
op = Operator.ADD;
calView.repaint();
}
/********************************************/
package lab5;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;

public class CalculateController implements ActionListener {
boolean digInputListener = false;

double data = 0;

String digStr = "";

String curStr = "";

CalculatorView calView = null;

Calculate cal = null;

CalculateState curCalState = null;

public static HashMap<String, Operator> operatorMap;
{
operatorMap = new HashMap<String, Operator>();
for (Operator p : Operator.values()) {
String str = p.toString();
operatorMap.put(str, p);
}
}

public CalculateController() {
}

public void setCalculate(Calculate c) {
cal = c;
curCalState = new InitCalculateState(this, cal);
}

public void addCalculateView(CalculatorView view) {
calView = view;
}

public Calculate getCalculate() {
return cal;
}

private void startDigInputListener() {
digInputListener = true;
data = 0;
digStr = "";
}

private void endDigInputListener() {
try {
digInputListener = false;
data = Double.parseDouble(digStr);
} catch (NumberFormatException e) {
cal.clear();
cal.setResult(0.0);
}
}

private void digInputListener(char d) {
digStr += d;
curStr = digStr;
cal.SetCurStr(digStr);
}

public void changeState(CalculateState newState) {
curCalState = newState;
}

public void actionPerformed(ActionEvent e) {
String str = e.getActionCommand();
char firstChar = str.charAt(0);

if ((firstChar <= '9' && firstChar >= '0') || firstChar == '.') {
if (digInputListener == false) {
startDigInputListener();
}
digInputListener(firstChar);
} else {
if (digInputListener == true) {
endDigInputListener();
curCalState.inputD(data);
}

Operator op = operatorMap.get(str);
passMessage(op);
}
}

private void passMessage(Operator op){
switch (op) {

case ADD:
case SUB:
case MUL:
case DIV:
curCalState.inputB(op);
break;

case COS:
case SIN:
case TAN:
curCalState.inputU(op);
break;
case ASSIGN:
curCalState.inputA();
break;
case CE:
curCalState.inputCE();
break;
case MR:
curCalState.inputMR();
break;
case M:
curCalState.inputM();
break;
case MC:
curCalState.inputMC();
break;
case MS:
curCalState.inputMS();
break;
}

}

public CalculatorView getCalculatorView() {
return calView;
}

public static void main(String[] args) {

CalculateController calController = new CalculateController();

CalculatorView mainView = new CalculatorView("Calculator",
calController);
Calculate cal = new Calculate(mainView);

calController.setCalculate(cal);
calController.addCalculateView(mainView);

}
}
****************************************************
package lab5;
public abstract class CalculateState {
protected CalculateController calController;

protected Calculate cal;

public CalculateState(CalculateController controller, Calculate c) {
calController = controller;
cal = c;
}

public void inputA() {

}

void inputD(double d) {

}

void inputU(Operator op) {

}

void inputB(Operator op) {

}
void inputCE(){
cal.clear();
}
/*
* 要存儲顯示的數據,請單擊「MS」。
* 要重新調用存儲的數據,請單擊「MR」。
* 要清除內存,請單擊「MC」。
* 把所顯示的數字與內存中的數字相加,請單擊「M+」
*/

void inputM(){
double curData = calController.getCalculatorView().getMainScreenData();
cal.setRgst(cal.getRgst() + curData);
}
void inputMR(){
inputD(cal.getRgst());
}
void inputMC(){
cal.setRgst(0);
}
void inputMS(){
double curData = calController.getCalculatorView().getMainScreenData();
cal.setRgst(curData);
}
}
******************************
package lab5;
import java.awt.*;
import javax.swing.*;

public class CalculatorView extends JFrame {
final static long serialVersionUID = 20000;

final int NUM = 24;

JButton[] buttons;

String[] texts = { "CE", "MC", "0", "1", "2", "+", "sin", "MR", "3", "4",
"5", "-", "cos", "MS", "6", "7", "8", "*", "tan", "M+", "9", ".",
"=", "/" };

JTextField rgstScreen;

JTextField mainScreen;

JPanel buttonPanel;

JPanel textPanel;

CalculateController calController = null;

public CalculatorView(String title, CalculateController controller) {
super(title);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
JFrame.(true);

calController = controller;

rgstScreen = new JTextField("0.0", 10);
mainScreen = new JTextField("0.0", 20);
rgstScreen.setEditable(false);
mainScreen.setFocusable(false);

textPanel = new JPanel();
textPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
textPanel.add(rgstScreen);
textPanel.add(mainScreen);

buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(4, 6));

buttons = new JButton[NUM];
for (int i = 0; i < NUM; i++) {
buttons[i] = new JButton(texts[i]);
buttons[i].addActionListener(calController);
buttons[i].setActionCommand(texts[i]);
buttonPanel.add(buttons[i]);
}

this.getContentPane().add(textPanel);
add(textPanel, BorderLayout.NORTH);
add(buttonPanel, BorderLayout.SOUTH);

pack();
setVisible(true);
}
public double getMainScreenData() {
return Double.parseDouble(mainScreen.getText());
}
public void repaint() {
super.repaint();
Calculate cal = calController.getCalculate();
mainScreen.setText(cal.getCurStr());
rgstScreen.setText(Double.toString(cal.getRgst()));
}

}
*************************************
package lab5;
public class InitCalculateState extends CalculateState {
public InitCalculateState(CalculateController controller, Calculate c) {
super(controller, c);
}

public void inputD(double d) {
OnlyOp1 s = new OnlyOp1(calController, cal);
calController.changeState(s);
s.inputD(d);
}
}

class OnlyOp1 extends CalculateState {
public OnlyOp1(CalculateController controller, Calculate c) {
super(controller, c);
}

public void inputA() {
}

public void inputD(double d) {
calController.getCalculate().setOp1(d);
calController.getCalculate().SetCurStr(Double.toString(d));
}

public void inputU(Operator op) {
UniqueOpState u = new UniqueOpState(calController, cal);
//cal.setOp(op);
calController.changeState(u);
u.inputU(op);
}

public void inputB(Operator op) {
WaitOp2 b = new WaitOp2(calController, cal);
calController.getCalculate().setOp(op);
calController.changeState(b);
}
}

class UniqueOpState extends CalculateState {

public UniqueOpState(CalculateController controller, Calculate c) {
super(controller, c);
}

public void inputA() {
dothing();
}

public void inputD(double d) {
OnlyOp1 w = new OnlyOp1(calController, cal);
calController.changeState(w);
w.inputD(d);
}

public void inputU(Operator op) {
cal.setOp(op);
dothing();
}

public void inputB(Operator op) {
WaitOp2 wOp2 = new WaitOp2(calController, cal);
cal.setOp(op);
calController.changeState(wOp2);
}

private void dothing() {
try {
double op1 = cal.result();
cal.setOp1(op1);
cal.SetCurStr(Double.toString(op1));
} catch (Exception e) {
cal.clear();
cal.setResult(0.0);
cal.SetCurStr("異常!");
}
}
}

class WaitOp2 extends CalculateState {

public WaitOp2(CalculateController controller, Calculate c) {
super(controller, c);
}

public void inputA() {
try {
double op2 = cal.getOp1();
cal.setOp2(op2);
double result = cal.result();
cal.setResult(result);
cal.setOp1(result);
cal.SetCurStr(Double.toString(result));
HaveOp2 b = new HaveOp2(calController, cal);
calController.changeState(b);
} catch (Exception e) {
cal.clear();
cal.setResult(0.0);
cal.SetCurStr("異常!");
}
}

public void inputD(double d) {
try {
cal.setOp2(d);
cal.SetCurStr(Double.toString(d));
cal.setResult(cal.result());
HaveOp2 b = new HaveOp2(calController, cal);
calController.changeState(b);
} catch (Exception e) {
cal.clear();
cal.setResult(0.0);

}
}

public void inputU(Operator op) {
UniqueOpState u = new UniqueOpState(calController, cal);
calController.changeState(u);
u.inputU(op);
}

public void inputB(Operator op) {
cal.setOp(op);
}
}

class HaveOp2 extends CalculateState {
public HaveOp2(CalculateController controller, Calculate c) {
super(controller, c);
}

public void inputA() {

try {
double result = cal.result();
cal.setResult(result);
cal.setOp1(result);
cal.SetCurStr(Double.toString(result));
} catch (Exception e) {
cal.clear();
cal.setResult(0.0);

}

}

public void inputD(double d) {
OnlyOp1 w = new OnlyOp1(calController, cal);
calController.changeState(w);
w.inputD(d);

}

public void inputU(Operator op) {
UniqueOpState u = new UniqueOpState(calController, cal);
calController.changeState(u);
u.inputU(op);
}

public void inputB(Operator op) {
WaitOp2 w = new WaitOp2(calController, cal);
double result = cal.getResult();
cal.setOp1(result);
cal.setOp(op);
cal.SetCurStr(Double.toString(result));
calController.changeState(w);
}
}
******************************
package lab5;

public enum Operator {
ADD, SUB, MUL, DIV, COS, SIN, TAN, CE, MR, MC, MS, M, ASSIGN;

public String toString() {

switch (this) {

case ADD:
return "+";
case SUB:
return "-";
case DIV:
return "/";
case MUL:
return "*";
case COS:
return "cos";
case SIN:
return "sin";
case TAN:
return "tan";
case CE:
return "CE";
case MR:
return "MR";
case MC:
return "MC";
case MS:
return "MS";
case M:
return "M+";
case ASSIGN:
return "=";
default:
return "Unkown Operator";

}
}

public static int OperatorType(Operator op) {
int type = 0;

switch (op) {

case ADD:
case SUB:
case MUL:
case DIV:
type = 2;
break;

case COS:
case SIN:
case TAN:
type = 1;
break;

default:
type = 3;
break;
}

return type;

}
}

public String getCurStr() {
return curStr;
}

public void SetCurStr(String str) {
curStr = str;
calView.repaint();
}

public void setOp1(double d) {
op1 = d;
calView.repaint();
}

public void setOp2(double d) {
op2 = d;
calView.repaint();
}

public void setOp(Operator p) {
op = p;
calView.repaint();
}

public void setResult(double result) {
this.result = result;
}

public double getOp1() {
return op1;
}

public double getOp2() {
return op2;
}

public Operator getOp() {
return op;
}
public double getResult(){
return result;
}
public double result() throws Exception{
double ret = 0;

switch (op) {
case ADD:
ret = op1 + op2;
break;

case SUB:
ret = op1 - op2;
break;

case MUL:
ret = op1 * op2;
break;

case DIV:
ret = op1 / op2;
break;

case SIN:
ret = Math.sin(op1);
break;

case COS:
ret = Math.cos(op1);
break;

case TAN:
ret = Math.tan(op1);
break;

}
return ret;
}

public double getRgst() {

return rgst;
}

public void setRgst(double m) {

this.rgst = m;
calView.repaint();
}
}

I. JAVA 編寫計算器 要代碼最簡單的

學java的時候自己編的,很簡單,能夠連續輸入計算式後進行計算
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**簡易計算器,能夠進行簡單的計算
*
* @see 2008.12.9
*/
public class CalculatorA
implements ActionListener{

private JFrame frame;
private JTextField field;
private JButton[] allButtons;
private JButton clearButton;
// private JButton backButton;
String result="";//保存結果
StringBuilder sb = new StringBuilder();//保存要進行的計算式
int x = 0; //用來判斷上一次的事件類型
String str = "123+456-789*0.=/";
ArrayList<String> arrayList = new ArrayList<String>();//保存計算式,通過方法進行運算

public CalculatorA(){

frame = new JFrame("我的計算器v1.1");
frame.setLocation(300,300);

field = new JTextField(25);

allButtons = new JButton[16];
for(int i=0;i<allButtons.length;i++){
allButtons[i]= new JButton(str.substring(i,i+1));
}
clearButton = new JButton("CLEAR");
// backButton = new JButton("<——");

init();
setFondAndColor();
addEventHander();
}

public void init(){
frame.setLayout(new BorderLayout());

JPanel northPanel = new JPanel();
JPanel centerPanel = new JPanel();
JPanel southPanel = new JPanel();

northPanel.setLayout(new FlowLayout());
centerPanel.setLayout(new GridLayout(4,4));
southPanel.setLayout(new FlowLayout());

northPanel.add(field);
for(int i=0;i<allButtons.length;i++){
centerPanel.add(allButtons[i]);
}
southPanel.add(clearButton);
//southPanel.add(backButton);

frame.add(northPanel,BorderLayout.NORTH);
frame.add(centerPanel,BorderLayout.CENTER);
frame.add(southPanel,BorderLayout.SOUTH);
}
//設置輸入字體
public void setFondAndColor(){
field.setFont(new Font("宋體",Font.BOLD,24));
field.setBackground(new Color(100,200,200));
field.setForeground(Color.RED);
//設置字體從右起始
field.setHorizontalAlignment(JTextField.RIGHT);
}

public void showMi(){
frame.pack();
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void addEventHander(){
for(int i=0;i<allButtons.length;i++){
allButtons[i].addActionListener(this);
}
clearButton.addActionListener(this);
// backButton.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
String str = e.getActionCommand();//取得當前事件返回的值
if("0123456789.".indexOf(str)!=-1){
if(x == 0){ //當x為0時表示還沒有進行輸入
result=str;
sb.append(str);
field.setText(str);
x = 1;
}
else if(x == 1){
result = result +str;
sb.append(str);
field.setText(result);
x = 1;
}
else if(x == 2){
sb.delete(0,sb.length());
result = result+str;
sb.append(str);
field.setText(result);
x = 1;
}
else if(x == 3){
result = str;
sb.delete(0,sb.length());
arrayList.clear();
field.setText(str);
sb.append(str);
field.setText(str);
x = 1;
}
else if(x == 4){
result ="";
sb.delete(0,sb.length());
arrayList.clear();
result = str;
sb.append(str);
field.setText(str);
x = 1;
}
else{
result = result +str;
sb.append(str);
field.setText(result);
x = 1;
}
}
else if("+*-/".indexOf(str)!=-1){
if(x == 0){
field.setText("");
x = 2;
}
else if(x == 1){
result = result + str;
arrayList.add(sb.toString());
arrayList.add(str);
sb.append(str);
field.setText(result);
x = 2;
}
else if(x == 2){
x = 2;
}
else if(x == 3){
field.setText(result+str);
arrayList.add(result);
arrayList.add(str);
result = result+str;
x = 2;
}
else if(x == 4){
result ="";
sb.delete(0,sb.length());
arrayList.clear();
x = 2;
}
else{
field.setText(result+str);
arrayList.add(result);
arrayList.add(str);
result = result+str;
x = 2;
}
}
else if("=".equals(str)){
if(x == 0){
field.setText("0");
arrayList.clear();
result = "0";
x = 3;
}
else if(x == 1){
try{
arrayList.add(sb.toString());
arrayList = getResult(arrayList);
result = arrayList.get(0);
field.setText(result);
arrayList.clear();
x = 3;
}catch(Exception e1){
field.setText("數據格式異常");
x = 0;
}
}
else if(x == 2){
field.setText("數據格式錯誤.....");
arrayList.clear();
x = 0;
}
else if(x == 3){
field.setText(result);
x = 3;
}
else if(x == 4){
result ="";
sb.delete(0,sb.length());
arrayList.clear();
x = 3;
}
else {
try{
arrayList.add(sb.toString());
arrayList = getResult(arrayList);
result = arrayList.get(0);
field.setText(result);
arrayList.clear();
x = 3;
}catch(Exception e1){
field.setText("數據格式異常");
x = 0;
}
}
}
else if("CLEAR".equals(str)){
arrayList.clear();
field.setText("0");
arrayList.add("0");
x = 4;
}
else{
if(result.length()>1){
result = result.substring(0,result.length()-1);
if(sb.length()>0){
sb.delete(sb.length()-1,sb.length());
}
else {
sb.delete(0,1);
}
field.setText(result);
x = 5;
}
else{
result = "";
sb.delete(0,sb.length());
arrayList.clear();
field.setText("0");
x = 0;
}
}
}
public static ArrayList<String> getResult(ArrayList<String> list){
String res = null;
String[] s = {"/","*","-","+"};
int i=0;
if(list.size()>1){
for(;i<s.length;){
if(s[i].equals("/")){
for(int j=0;j<list.size();j++){
if(list.get(j).equals(s[i])){
res = Double.toString(Double.parseDouble(list.get(j-1))/Double.parseDouble(list.get(j+1)));
//本地的數據格式
NumberFormat nf = NumberFormat.getInstance();
res = nf.format(Double.parseDouble(res));
res = getChange(res);
list.set(j-1,res);
list.remove(j);
list.remove(j);
getResult(list);
}
}
i++;
}
else if(s[i].equals("*")){
for(int j=0;j<list.size();j++){
if(list.get(j).equals(s[i])){
res = Double.toString(Double.parseDouble(list.get(j-1))*Double.parseDouble(list.get(j+1)));
NumberFormat nf = NumberFormat.getInstance();
res = nf.format(Double.parseDouble(res));
res = getChange(res);
list.set(j-1,res);
list.remove(j);
list.remove(j);
getResult(list);
}
}
i++;
}
else if(s[i].equals("-")){
for(int j=0;j<list.size();j++){
if(list.get(j).equals(s[i])){
res = Double.toString(Double.parseDouble(list.get(j-1))-Double.parseDouble(list.get(j+1)));
NumberFormat nf = NumberFormat.getNumberInstance();
res = nf.format(Double.parseDouble(res));
res = getChange(res);
list.set(j-1,res);
list.remove(j);
list.remove(j);
getResult(list);
}
}
i++;
}
else {
for(int j=0;j<list.size();j++){
if(list.get(j).equals(s[i])){
res = Double.toString(Double.parseDouble(list.get(j-1))+Double.parseDouble(list.get(j+1)));
NumberFormat nf = NumberFormat.getInstance();
res = nf.format(Double.parseDouble(res));
res = getChange(res);
list.set(j-1,res);
list.remove(j);
list.remove(j);
getResult(list);
}
}
i++;
}
}
}
return list;
}
//對數字字元串進行排除不必要符號
public static String getChange(String res){
String s_temp = "";
char[] c = new char[res.length()];
for(int k=0;k<c.length;k++){
c[k] = res.charAt(k);
}
for(int k=0;k<c.length;k++){
if((c[k]>= '0' && c[k]<= '9')|| c[k] == '.'){
s_temp += c[k];
}
}
return s_temp;
}
public static void main(String[] args){
new CalculatorA().showMi();
}
}

J. 用C語言設計一個簡單計算器

#include<stdio.h>
voidadd(inta,intb,intc)
{
c=a+b;
printf("%d ",c);
printf(" ");
}
voidminus(inta,intb,intc)
{
c=a-b;
printf("%d ",c);
printf(" ");
}
voidmultiplication(inta,intb,intc)
{
c=a*b;
printf("%d ",c);
printf(" ");
}
voiddiv(inta,intb,intc)
{
c=(float)a/(float)b;
printf("%f ",c);
printf(" ");
}
main()
{
inta,b,c;
charp;
puts("inputA: ");
scanf("%d",&a);
puts("inputB: ");
scanf("%d",&b);
puts("inputoperation: ");
getchar();
p=getchar();
if(p=='+')add(a,b,c);else
if(p=='-')minus(a,b,c);else
if(p=='*')multiplication(a,b,c);else
if(p=='/')div(a,b,c);else
puts("沒有注冊這個運算符號 ");
}

以上是設計的一個簡易計算器。可以進行相應的加減乘除。

熱點內容
手機優酷緩存視頻格式 發布:2025-05-15 04:13:45 瀏覽:209
公益電影分鏡頭腳本插畫 發布:2025-05-15 04:08:37 瀏覽:960
數據壓縮編碼 發布:2025-05-15 03:58:44 瀏覽:725
java字元為空 發布:2025-05-15 03:57:11 瀏覽:546
速訊安卓哪裡下載 發布:2025-05-15 03:55:02 瀏覽:48
緩存區數據讀寫原理 發布:2025-05-15 03:39:57 瀏覽:585
編譯器生成的是二進制文件嗎 發布:2025-05-15 03:38:42 瀏覽:955
運營為什麼區分ios和安卓 發布:2025-05-15 03:30:02 瀏覽:630
主播網站源碼 發布:2025-05-15 02:50:56 瀏覽:168
中文編程語言有哪些 發布:2025-05-15 02:48:59 瀏覽:536