乙個簡單的計算器模擬程式 2011騰訊筆試填空題

2021-06-13 06:58:15 字數 703 閱讀 8383

【說明】

本程式是乙個簡單計算器模擬程式。對任意給定的正確四則運算表示式,程式計算其結果值並輸出。表示式中運算分量為無正負號的整數,運算子為+ - * / ,圓括號按常規配對,表示式以字元「=」結束。

函式getch()為獲取表示式的乙個合法字元,並將字元存入變數curch;函式指標陣列func是為了統一加減乘除計算而設定的。(紅色為需要補充的部分)

#include

#include

#include

int add_fun(int x,int y)

int sub_fun(int x,int y)

int mul_fun(int x,int y)

int div_fun(int x,int y)

int (*func)(int,int)=;

int num,curch;

char chtbl="+-*/()=";

char corch="+-*/()=0123456789";

int getch()

return curch;

}int getid()

else

}int cal()

op2=getid();

}return (*func[op1])(x1,x2);

}int main(int argc,char *argv)

return 0;

}

乙個簡單的計算器

乙個非常簡單的計算器 來自sololearn 只能進行單一計算 while true print 設定 print enter 增加 to 增加 two numbers print enter 減去 to 減去 two numbers print enter 相乘 to 相乘 two numbers...

製作乙個簡單的計算器

coding utf 8 time 2020 2 5 author wowilliam210 file calculator.py software pycharm import win32com.client class acalculator object def check num zsq f...

乙個極簡單的計算器

網上看到的計算器程式,再加上一些對於 號的處理,就完美了,例如輸入 3 6 8敲回車,立刻就列印出51,如果輸入3 6 8 則出錯,這兒需處理一下.import os while true dynamic input 輸入計算表示式 if dynamic cls try result eval dy...