當前位置:首頁 » 編程軟體 » 編程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-07-09 13:38:07 瀏覽:771
雙加密狗 發布:2025-07-09 13:26:51 瀏覽:471
1加5t買什麼配置合適 發布:2025-07-09 13:17:51 瀏覽:540
mssql分頁存儲過程 發布:2025-07-09 13:17:00 瀏覽:271
cpython模塊擴展 發布:2025-07-09 13:16:11 瀏覽:95
linux安裝mysql步驟 發布:2025-07-09 13:02:48 瀏覽:158
ant編譯flex 發布:2025-07-09 12:57:10 瀏覽:787
光洋編程中文 發布:2025-07-09 12:56:14 瀏覽:418
安卓的高德地圖哪個好 發布:2025-07-09 12:50:34 瀏覽:220
2008資料庫密鑰 發布:2025-07-09 12:42:23 瀏覽:969