當前位置:首頁 » 編程軟體 » 編程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;
}

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:588
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:884
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:576
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:762
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:679
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1009
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:252
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:110
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:801
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:708