当前位置:首页 » 编程软件 » 编程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 浏览:961
车配置字母怎么看 发布:2025-09-16 10:09:32 浏览:401
烟台电脑服务器维修 发布:2025-09-16 10:08:45 浏览:261
编译命令cl 发布:2025-09-16 09:57:21 浏览:513
小君直播密码是多少 发布:2025-09-16 09:25:46 浏览:602
用中文编译的编程软件 发布:2025-09-16 09:04:37 浏览:145
语音编译器教程 发布:2025-09-16 08:57:44 浏览:450
sql注册服务器 发布:2025-09-16 08:53:17 浏览:613
嵌入式linuxc编程入门 发布:2025-09-16 08:24:18 浏览:387
码片编程器 发布:2025-09-16 08:24:08 浏览:956