當前位置:首頁 » 編程軟體 » 編程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解析json文件 發布:2025-09-16 10:10:41 瀏覽:960
車配置字母怎麼看 發布:2025-09-16 10:09:32 瀏覽:400
煙台電腦伺服器維修 發布:2025-09-16 10:08:45 瀏覽:260
編譯命令cl 發布:2025-09-16 09:57:21 瀏覽:512
小君直播密碼是多少 發布:2025-09-16 09:25:46 瀏覽:601
用中文編譯的編程軟體 發布:2025-09-16 09:04:37 瀏覽:144
語音編譯器教程 發布:2025-09-16 08:57:44 瀏覽:449
sql注冊伺服器 發布:2025-09-16 08:53:17 瀏覽:612
嵌入式linuxc編程入門 發布:2025-09-16 08:24:18 瀏覽:386
碼片編程器 發布:2025-09-16 08:24:08 瀏覽:955