當前位置:首頁 » 編程軟體 » 編程opt

編程opt

發布時間: 2023-08-29 00:57:29

❶ 用C語言編程實現一個簡單的四則運算計算器

#include <stdio.h>

//函數,讀數操作數
int getNextNum()
{
int ret;
scanf("%d",&ret);
return ret;
}

//函數,讀運算符
char getOpt()
{
return getchar();
}

//函數,計算
int caculate(int op1 , int op2 ,char opt)
{
if(opt=='+')return op1+op2;
if(opt=='-')return op1-op2;
if(opt=='*')return op1*op2;
if(opt=='/')return op1/op2;
return 0;
}

int main()
{
int op1,op2;
char opt;
//計算結果放在第一個操作數
op1 = getNextNum();
while(1)
{
opt = getOpt();
if ( opt == '=' ) break;
op2 = getNextNum();
op1 = caculate(op1,op2,opt);
}
printf("%d\n",op1);
}
return 0;
}

熱點內容
什麼編程軟體最好 發布:2025-03-15 05:57:13 瀏覽:600
安卓手機怎麼看國內 發布:2025-03-15 05:43:01 瀏覽:729
游戲中心密碼在哪裡看 發布:2025-03-15 05:41:09 瀏覽:941
微信支付android開發 發布:2025-03-15 05:29:35 瀏覽:656
密度值演算法 發布:2025-03-15 05:26:41 瀏覽:318
暑期學編程 發布:2025-03-15 05:21:33 瀏覽:346
加密與 發布:2025-03-15 05:21:25 瀏覽:720
安卓如何把時鍾插件調出來 發布:2025-03-15 05:19:11 瀏覽:50
安卓旋鈕主機音量大小怎麼調整 發布:2025-03-15 05:19:05 瀏覽:755
如何將支付密碼關掉 發布:2025-03-15 05:16:55 瀏覽:933